Signal Channels

A signal channel is one that is used just for signaling. Put simply, we can use a signal channel when we want to inform another goroutine about something. Signal channels should not be used for data transfer. Let’s explore the use of signal channels to specify the order of execution of goroutines.

Specifying the order of execution for our goroutines

This lesson shows a technique for specifying the order of execution of goroutines with the help of signal channels. However, keep in mind that this technique works best when we are dealing with a small number of goroutines. The presented code example has four goroutines that we want to execute in the desired order—first, goroutine for function A(), then function B(), then C(), and finally, D().

Coding example

The code of defineOrder.go without the package statement and import block is the following:

Get hands-on with 1200+ tech skills courses.