Skip to content

Instantly share code, notes, and snippets.

@col3name
Created February 16, 2022 19:50
Show Gist options
  • Select an option

  • Save col3name/8136af837b9300cf07609f3cccaea2f2 to your computer and use it in GitHub Desktop.

Select an option

Save col3name/8136af837b9300cf07609f3cccaea2f2 to your computer and use it in GitHub Desktop.
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