Skip to content

Instantly share code, notes, and snippets.

@emepyc
Created March 16, 2012 13:24
Show Gist options
  • Save emepyc/2050049 to your computer and use it in GitHub Desktop.
Save emepyc/2050049 to your computer and use it in GitHub Desktop.
package main
import (
"time"
"runtime"
"fmt"
)
var (
closeRead = make(chan bool)
qstate = make(chan int, 8)
)
func init() {
runtime.GOMAXPROCS(2)
}
func main() {
go runRead()
for s := range qstate {
fmt.Println(s)
if s == 1 {
closeRead <- true
}
}
}
func runRead() {
stopRead := false
count := 0
for {
select {
case <- closeRead:
return
default:
if stopRead {
fmt.Println("stopRead")
break
}
count ++
if count == 10 {
stopRead = true
qstate <- 1 //
close(qstate)
break
} else {
time.After(100000000)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment