image.png
package main
import "fmt"
func main() {
message := make( chan string)
go func() {
message <- "hello goroutine!"
}()
str := <-message
fmt.Println(str)
fmt.Println("hello")
}
package main
import (
"fmt"
"time"
)
func main() {
message := make( chan string)
go func() {
message <- "hello goroutine!"
}()
go func() {
time.Sleep(2*time.Second)
str := <-message
str = str + "I'm goroutine!"
message <- str
}()
time.Sleep(3*time.Second)
str := <-message
fmt.Println(str)
fmt.Println("hello")
}
image.png
image.png
image.png image.png image.png
image.png image.png
image.png
image.png
image.png
image.png
image.png
image.png
网友评论