Created
October 17, 2018 20:55
-
-
Save stackdump/7256089d4d822fa87a46ac7b5914b9d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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