Skip to content

Instantly share code, notes, and snippets.

@gocs

gocs/goroutine.go

Created Apr 8, 2019
Embed
What would you like to do?
goroutine that counts while sleeping
package main
import (
"fmt"
"time"
)
func count(quit chan bool) {
count := 0
for {
select {
case <-quit:
fmt.Println("\n\t\ttotal:", count)
return
default:
}
count++
fmt.Print(".") // to print the `quit` reciever case
}
}
func main() {
quit := make(chan bool)
go count(quit)
time.Sleep(time.Second / 100)
quit <- true // forces `count` to do job
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.