yeast/tools/parallel.go
2014-08-24 19:56:55 +07:00

23 lines
436 B
Go

package tools
import (
"code.google.com/p/go.net/context"
)
func SyncronizeParallelChain(ctx context.Context, fn func(context.Context)) {
var (
pcontexts = ctx.Value("parallel_contexts").(chan context.Context)
pfinished = ctx.Value("parallel_finished").(chan struct{})
working = true
)
for len(pcontexts) > 0 || working {
select {
case pctx := <-pcontexts:
fn(pctx)
case <-pfinished:
working = false
}
}
}