Send statements
一个发送语句将一个值发送到通道。其中的 Expression 必须为 通道类型,并且通道方向需要支持发送操作、 发送的值必须是可以 赋值 给通道的元素类型的。
SendStmt = Channel "<-" Expression .
Channel = Expression .
在开始通信之前将对通道和值表达式进行评估,通信将阻塞至可以发送。如果接收器准备就绪,则可以在无缓冲的通道上进行发送。如果缓冲区中有空间,则可以在缓冲通道上进行发送。在关闭的通道上发送会引起运行时恐慌。在nil
通道上的发送将永远阻塞。
ch <- 3 // 向通道 ch 发送值 3
Both the channel and the value expression are evaluated before communication begins. Communication blocks until the send can proceed. A send on an unbuffered channel can proceed if a receiver is ready. A send on a buffered channel can proceed if there is room in the buffer. A send on a closed channel proceeds by causing a run-time panic. A send on a nil
channel blocks forever.
ch <- 3 // send value 3 to channel ch
本译文仅用于学习和交流目的,转载请务必注明文章译者、出处、和本文链接
我们的翻译工作遵照 CC 协议,如果我们的工作有侵犯到您的权益,请及时联系我们。