HomeToolsAbout

Receive

Receive Operator (<-)

Think of a channel as a message queue.

If the channel is on the right of the receive operator, it means to dequeue an entry.

  • Saving the entry in a variable is optional.
e <- q

If the channel is on the left of the receive operator, it means to enqueue an entry.

q <- e

Further note about "dequeue" (receive) without storing in a variable: it can be used on a non-buffered queue to implement something like a "wait/notify" operation in Java: One coroutine is blocked waiting to dequeue/receive a signal, then another coroutine enqueues/sends that signal, the content of which is unimportant. (alternately, the sender could be blocked until the receiver pulls out the message).

AboutContact