Created
March 16, 2012 13:24
-
-
Save emepyc/2050049 to your computer and use it in GitHub Desktop.
This file contains 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" | |
"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