Skip to content

Instantly share code, notes, and snippets.

@jkassemi
Created January 5, 2014 07:19
Show Gist options
  • Save jkassemi/8265426 to your computer and use it in GitHub Desktop.
Save jkassemi/8265426 to your computer and use it in GitHub Desktop.
Run until all or condition met
drain := make(chan bool, len(tasks))
answer := make(chan interface{}, 1)
drained := make(chan bool, 1)
for _, v := range tasks {
go func(){
defer func(){
drain <- true
}()
// Find an answer
// answer <- myAnswer
}()
}
go func(){
for i:=0;i<len(tasks);i+=1 {
<-drain
}
}()
select {
case <-drained:
return nil
case a := <-answer:
return a
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment