Introduction
This challenge aims to test your knowledge of using channels to synchronize execution across goroutines.
This tutorial is from open-source community. Access the source code
This challenge aims to test your knowledge of using channels to synchronize execution across goroutines.
The problem to be solved in this challenge is to create a goroutine that performs some work and notifies another goroutine when it's done using a channel.
To complete this challenge, you will need to:
worker
that takes a channel of type bool
as a parameter.worker
function, perform some work and then send a value to the channel to notify that the work is done.main
function, create a channel of type bool
with a buffer size of 1.worker
function and passes the channel as a parameter.main
function until a value is received from the channel.$ go run channel-synchronization.go
working...done
## If you removed the `<- done` line from this program, the
## program would exit before the `worker` even
## started.
In this challenge, you learned how to use channels to synchronize execution across goroutines. By creating a channel and passing it to a goroutine, you can wait for the goroutine to finish its work and notify you when it's done.