Quit Channel

In this lesson, we'll study a pattern related to quitting from a select statement.

You will notice that you have probably seen the quit channel pattern in the coding examples before. Let’s discover more about it!

So we’ll set up a car race competition. In the code below, we launch three goroutines by calling the Race function in a for-loop. Now we are only interested in the race until one of the cars reaches the finishing line. Let’s see how it’s done:

Get hands-on with 1400+ tech skills courses.