Skip to content

Commit

Permalink
feat(buffer): Added a buffer func for data sinks
Browse files Browse the repository at this point in the history
  • Loading branch information
marksalpeter committed Sep 2, 2021
1 parent de00a95 commit e568cb1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions buffer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package pipeline

// Buffer creates a buffered channel that will close after the input
// is closed and the buffer is fully drained
func Buffer(size int, in <-chan interface{}) <-chan interface{} {
buffer := make(chan interface{}, size)
go func() {
for i := range in {
buffer <- i
}
close(buffer)
}()
return buffer
}

0 comments on commit e568cb1

Please sign in to comment.