~kotrunga/a-tour-of-go

a-tour-of-go/concurrency/3.1_goroutines.go -rw-r--r-- 417 bytes View raw
b3f98925kotrunga remove .DS_Store file 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
	Notes 3.1

	A 'goroutine' is a "lightweight thread managed by the Go runtime".

	If you run go f(x, y, z), it evaluates f, x, y, and z on the current goroutine, and
	the execution of f happens in the new goroutine.
*/

package main

import (
	"fmt"
	"time"
)

func say(s string) {
	for i := 0; i < 5; i++ {
		time.Sleep(100 * time.Millisecond)
		fmt.Println(s)
	}
}

func main() {
	go say("world")
	say("hello")
}