Skip to content

Instantly share code, notes, and snippets.

@nicewook
Created July 29, 2020 10:49
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 nicewook/46dbb771a2755044f4d6daa45fa8abba to your computer and use it in GitHub Desktop.
Save nicewook/46dbb771a2755044f4d6daa45fa8abba to your computer and use it in GitHub Desktop.
orDone := func(done, c <-chan interface{}) <-chan interface{} {
valStream := make(chan interface{})
go func() {
defer close(valStream)
for {
select {
case <-done:
return
case v, ok := <-c:
if ok == false {
return
}
select {
case valStream <- v:
case <-done:
}
}
}
}()
return valStream
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment