-
Notifications
You must be signed in to change notification settings - Fork 7
/
util.go
28 lines (24 loc) · 1.06 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package rill
import "github.com/destel/rill/internal/core"
// Drain consumes and discards all items from an input channel, blocking until the channel is closed.
func Drain[A any](in <-chan A) {
core.Drain(in)
}
// DrainNB is a non-blocking version of [Drain]. It does draining in a separate goroutine.
func DrainNB[A any](in <-chan A) {
core.DrainNB(in)
}
// Buffer takes a channel of items and returns a buffered channel of exact same items in the same order.
// This can be useful for preventing write operations on the input channel from blocking, especially if subsequent stages
// in the processing pipeline are slow.
// Buffering allows up to size items to be held in memory before back pressure is applied to the upstream producer.
//
// Typical usage of Buffer might look like this:
//
// users := getUsers(ctx, companyID)
// users = rill.Buffer(users, 100)
// // Now work with the users channel as usual.
// // Up to 100 users can be buffered if subsequent stages of the pipeline are slow.
func Buffer[A any](in <-chan A, size int) <-chan A {
return core.Buffer(in, size)
}