go:goroutine
This commit is contained in:
parent
1a4517a49f
commit
c57f8e4a86
19
go/goroutine/main.go
Normal file
19
go/goroutine/main.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func delay_string(str string) {
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
fmt.Println(str)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
go delay_string("world!")
|
||||||
|
fmt.Println("hello")
|
||||||
|
// Added to avoid the program ending before the routine finished
|
||||||
|
time.Sleep(100 * time.Millisecond * 2)
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user