Skip to content

Commit

Permalink
doc: add ChannelMerge
Browse files Browse the repository at this point in the history
  • Loading branch information
samber committed Oct 14, 2022
1 parent d899a1c commit a14c1b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ Supported helpers for channels:
- [Generator](#generator)
- [Batch](#batch)
- [BatchWithTimeout](#batchwithtimeout)
- [ChannelMerge](#channelmerge)

Supported intersection helpers:

Expand Down Expand Up @@ -1397,7 +1398,7 @@ Returns a read-only channels of collection elements. Channel is closed after las
list := []int{1, 2, 3, 4, 5}

for v := range lo.SliceToChannel(2, list) {
println(v)
println(v)
}
// prints 1, then 2, then 3, then 4, then 5
```
Expand Down Expand Up @@ -1529,6 +1530,18 @@ for i := range children {
}
```

### ChannelMerge

Collects messages from multiple input channels into a single buffered channel. Output messages has no priority.

```go
stream1 := make(chan int, 42)
stream2 := make(chan int, 42)
stream3 := make(chan int, 42)

all := lo.ChannelMerge(100, stream1, stream2, stream3)
```

### Contains

Returns true if an element is present in a collection.
Expand Down
4 changes: 2 additions & 2 deletions channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ func BatchWithTimeout[T any](ch <-chan T, size int, timeout time.Duration) (coll
return buffer, index, time.Since(now), true
}

// ChannelMerge collect messages from multiple input channels into one buffered channel.
// output messages has no order guarantee
// ChannelMerge collects messages from multiple input channels into a single buffered channel.
// Output messages has no priority.
func ChannelMerge[T any](channelBufferCap int, upstreams ...<-chan T) <-chan T {
out := make(chan T, channelBufferCap)
var wg sync.WaitGroup
Expand Down

0 comments on commit a14c1b2

Please sign in to comment.