goroutines-async-channel-send-receive-waiting example
Sending data to a goroutine via an async channel.
Both SEND and RCV will block/wait for data.
These are my 5 main example of using goroutines,
GitHub Webpage
CHANNELS (MESSAGE PASSING)
Giving a channel msgCh
,
Send,
msgCh <- "Jeff" // WAITS/BLOCKS
Receive,
say = <-msgCh // ALSO WAITS/BLOCKS
RUN
go run goroutines-async-channel-send-receive-waiting.go
Simply press return to exit.
Output is always,
Sent message Jeff
0 Received message Jeff
Sent message Clif
1 Received message Clif
Sent message Jack
2 Received message Jack
Sent message Jill
3 Received message Jill
Try slowing down or speeding up the SEND or RCV and you will always
get the same result because both sides block/wait.