2 ms·
resume/yield gives you these features of channels: - time ordering (in both, the send "happens before" the receive, and the next line in the sender "happens af
by JulianMorrison 13y ago
resume/yield gives you these features of channels:
- time ordering (in both, the send "happens before" the receive, and the next line in the sender "happens after" the receive)
- communication
- pipelined architecture
but not these:
- the runtime chooses a goroutine that can proceed and schedules it, you don't need to fear blocking, producers can make headway while consumers are waiting, and you don't need to manually arrange multi-goroutine control flow into some sort of pass-the-buck loop.
- nonblocking sends allow a variation of the time ordering (the send "happens before" the receive, but the next line in the sender is not coordinated with the receiver, it may happen immediately)
- decoupling sender and recipient: the recipient goroutine doesn't need to know which goroutine to resume such that the sender can pick up where it left off
- ability to choose which channel you'll communicate down,
--- simultaneously, whichever is ready (listen for "shutdown", "timeout" and "data", for example) and with a default that can be used for the non-blocking alternative
--- at different times in one goroutine (read "producer" then write "consumer" then read "status" then write "confirmation", for example - you can do this in stock Lua but the coupling would be awful)