Skip to content

Instantly share code, notes, and snippets.

@denisvmedia
Created June 15, 2017 09:01
Show Gist options
  • Save denisvmedia/4a18b60e58de42cff3e91ce9986cd325 to your computer and use it in GitHub Desktop.
Save denisvmedia/4a18b60e58de42cff3e91ce9986cd325 to your computer and use it in GitHub Desktop.
Quit by closing channel
package main
import "sync"
import "fmt"
import "time"
func main() {
quit := make(chan interface{}, 10)
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
for {
select {
case <-quit:
fmt.Println("exited")
wg.Done();
return
default:
time.Sleep(time.Second / 2)
fmt.Println("waiting")
}
}
}()
time.Sleep(time.Second * 20)
close(quit)
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment