Skip to content

Instantly share code, notes, and snippets.

@benschw
Created Sep 15, 2014
Embed
What would you like to do?
concurent pipeline processing in go
package main
import (
"log"
"strconv"
"time"
)
var _ = log.Print
func genWork(queue chan int, sig chan bool) {
for i := 0; i < 10; i++ {
log.Print("q " + strconv.FormatInt(int64(i), 10))
queue <- i
}
close(queue)
sig <- true
}
func doWork(queue chan int, sig chan bool) {
time.Sleep(1000 * time.Millisecond)
for val := range queue {
log.Print("d " + strconv.FormatInt(int64(val), 10))
}
log.Print("done working")
sig <- true
}
func main() {
queue := make(chan int, 20)
genSig := make(chan bool, 1)
doSig := make(chan bool, 1)
go genWork(queue, genSig)
go doWork(queue, doSig)
log.Print("outer")
<-genSig
<-doSig
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment