标签:
func main() {
var jobs = Chan<Int>(buffer: 5)
var done = Chan<Bool>()
go {
for ;; {
var (j, more) = <?jobs
if more {
println("received job \(j!)")
} else {
println("received all jobs")
done <- true
return
}
}
}
for var j = 1; j <= 3; j++ {
jobs <- j
println("sent job \(j)")
}
close(jobs)
println("sent all jobs")
<-done
}
标签:
原文地址:http://my.oschina.net/chai2010/blog/465054