concurrent goroutines
This commit is contained in:
25
gobyexample/goroutines.go
Normal file
25
gobyexample/goroutines.go
Normal file
@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func f(from string) {
|
||||
for i := 0; i < 3; i++ {
|
||||
fmt.Println(from, ":", i)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
f("direct")
|
||||
|
||||
go f("goroutine")
|
||||
|
||||
go func(msg string) {
|
||||
fmt.Println(msg)
|
||||
}("going")
|
||||
|
||||
time.Sleep(time.Second)
|
||||
fmt.Println("done")
|
||||
}
|
Reference in New Issue
Block a user