...

/

Quit Channel

Quit Channel

Learn how to stop a goroutine.

Overview of the Quit channel

One goroutine can’t forcibly stop another. A gorou­tine can stop only by returning from its top-level function. We can’t kill a goroutine from outside. We can signal to a goroutine to stop using a channel. For example, suppose our goroutine looks like the following:

ch := make(chan string, 10)
go func(){
    for {
        ch <- do_stuff()
    }
}()

The ...