Created
July 29, 2020 10:49
-
-
Save nicewook/46dbb771a2755044f4d6daa45fa8abba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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