mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 03:55:28 +08:00
24 lines
282 B
Go
Executable File
24 lines
282 B
Go
Executable File
package main
|
|
|
|
import "fmt"
|
|
import "time"
|
|
|
|
func main() {
|
|
c := make(chan int)
|
|
go func() {
|
|
time.Sleep(15 * 1e9)
|
|
x := <-c
|
|
fmt.Println("received", x)
|
|
}()
|
|
fmt.Println("sending", 10)
|
|
c <- 10
|
|
fmt.Println("sent", 10)
|
|
}
|
|
|
|
/* Output:
|
|
sending 10
|
|
(15 s later):
|
|
received 10
|
|
sent 10
|
|
*/
|