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 }原文链接:https://www.f2er.com/swift/326987.html