-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathutil.go
More file actions
35 lines (30 loc) · 1.24 KB
/
util.go
File metadata and controls
35 lines (30 loc) · 1.24 KB
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
29
30
31
32
33
34
35
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)
}
// Discard is a non-blocking function that discards all items from an input channel.
func Discard[A any](in <-chan A) {
core.Discard(in)
}
// DrainNB is a non-blocking version of [Drain]. It does draining in a separate goroutine.
//
// Deprecated: use [Discard] instead
func DrainNB[A any](in <-chan A) {
core.Discard(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)
}