Skip to content

Commit e7006e0

Browse files
committed
Fan-in-out docs
1 parent f98982b commit e7006e0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,24 @@ which consolidates multiple data streams into a single unified channel.
146146
Fan-out is done with the **Split2** function, that divides a single input stream into two distinct output channels.
147147
This division is based on a discriminator function, allowing parallel processing paths based on data characteristics.
148148

149+
When splitting a stream, you create a scenario with a single producer and two consumers.
150+
It's important to note that if one consumer is blocked, it can lock the entire pipeline,
151+
affecting the producer and the other consumer.
152+
One way to mitigate this is to use a buffer on the output channels, but be aware that this will increase memory usage.
153+
154+
```go
155+
out1, out2 := rill.Split2(input, 10, func(item string) bool {
156+
// Some splitting logic...
157+
})
158+
159+
// out1 is slow. Buffer up to 100 items that go to it
160+
out1 = rill.Buffer(out1, 100)
161+
162+
// Now, work with out1 and out2 as usual
163+
```
164+
165+
166+
149167

150168

151169
## Error handling

0 commit comments

Comments
 (0)