-
-
Save col3name/8136af837b9300cf07609f3cccaea2f2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package h_execution //nolint:golint,stylecheck | |
| type ( | |
| I = interface{} | |
| In = <-chan I | |
| Out = In | |
| Bi = chan I | |
| ) | |
| type Stage func(in In) (out Out) | |
| func ExecutePipeline(in In, done In, stages ...Stage) Out { | |
| out := in | |
| for _, stage := range stages { | |
| bi := make(Bi) | |
| go func(b Bi, o Out) { | |
| defer close(b) | |
| for { | |
| select { | |
| case <-done: | |
| return | |
| case v, ok := <-o: | |
| if !ok { | |
| return | |
| } | |
| b <- v | |
| } | |
| } | |
| }(bi, out) | |
| out = stage(bi) | |
| } | |
| return out | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment