Go实例: Non-Blocking Channel Operations

Oriel ·
更新时间:2024-11-13
· 304 次阅读

package main import "fmt" func main() { messages := make(chan string) signals := make(chan bool) select { case msg := <-messages: fmt.Println("received message", msg) default: fmt.Println("no message received") } msg := "hi" select { case messages <- msg: fmt.Println("sent message", msg) default: fmt.Println("no message sent") } select { case msg := <-messages: fmt.Println("received message", msg) case sig := <-signals: fmt.Println("received signal", sig) default: fmt.Println("no activity") } }$ go run non-blocking-channel-operations.go no message received no message sent no activity



GO实例 GO

需要 登录 后方可回复, 如果你还没有账号请 注册新账号