有界通道
With bounded (synchronous) channels, send
can block the current thread:
Speaker Notes
- 调用
send
将阻塞当前线程,直到通道中有足够的空间放置新消息。如果无人从通道读取数据,线程会被无限期地阻塞。 - 如果通道关闭,调用
send
将中止并返回错误(这就是它会返回Result
的原因)。当接收器被丢弃时,通道将关闭。 - 大小为零的有界通道称为 “集合通道”。每次调用 send 都会阻塞当前线程,直到另一个线程调用
read
。