Skip to content

Instantly share code, notes, and snippets.

@jamesharr
Last active December 21, 2015 22:09
Show Gist options
  • Save jamesharr/6373620 to your computer and use it in GitHub Desktop.
Save jamesharr/6373620 to your computer and use it in GitHub Desktop.
recv := make(chan int)
send := make(chan int)
go func() {
queue = make([]int, 0)
done := false
for !done {
if len(queue) == 0 {
select {
case item, ok := <-recv:
if ok {
queue = append(queue, item)
} else {
done = true
}
}
} else {
select {
case send <- queue[0]: // <-- can I conditionally exclude this case from selects?
queue = queue[1:]
case item, ok := <-recv:
if ok {
queue = append(queue, item)
} else {
done = true
}
}
}
}
}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment