Introduction
This challenge aims to test your knowledge of Go's select
statement, which allows you to wait on multiple channel operations.
This challenge aims to test your knowledge of Go's select
statement, which allows you to wait on multiple channel operations.
In this challenge, you are given two channels, c1
and c2
, which will receive a value after some amount of time. Your task is to use select
to await both of these values simultaneously, printing each one as it arrives.
select
statement to wait on both channels.## We receive the values `"one"` and then `"two"` as
## expected.
$ time go run select.go
received one
received two
## Note that the total execution time is only ~2 seconds
## since both the 1 and 2 second `Sleeps` execute
## concurrently.
real 0m2.245s
This challenge tests your ability to use the select
statement in Go to wait on multiple channel operations. By completing this challenge, you will gain a better understanding of how to use select
to coordinate concurrent goroutines.