Exercise: Buzz Game
Let's implement a buzz game using the tools we have learnt so far!
In the code below, you will find two goroutines which represent our players and send messages over channels signaling Buzz
to the main routine. Now the problem with the code below is that channel1
blocks the code, which implies that we can’t receive any message from channel2
until we receive a message from channel1
. Therefore, if player 2, i.e. the second goroutine buzzes before player 1, we’ll never be able to know!
Get hands-on with 1400+ tech skills courses.