Skip to content

Instantly share code, notes, and snippets.

@benschw
Created September 15, 2014 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benschw/09f3a91e8bba7872120a to your computer and use it in GitHub Desktop.
Save benschw/09f3a91e8bba7872120a to your computer and use it in GitHub Desktop.
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