Skip to content

Instantly share code, notes, and snippets.

@stackdump
Created October 17, 2018 20:55
Show Gist options
  • Save stackdump/7256089d4d822fa87a46ac7b5914b9d4 to your computer and use it in GitHub Desktop.
Save stackdump/7256089d4d822fa87a46ac7b5914b9d4 to your computer and use it in GitHub Desktop.
package main
import "time"
func main() {
stop := make(chan struct{})
go func() {
//wait := time.After(500 * time.Millisecond)
//<-wait
time.Sleep(time.Millisecond * 500)
println("stopping")
close(stop)
}()
loop:
for {
select {
case <-stop: // triggered when the stop channel is closed
break loop // exit
default:
println("foo")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment