mirror of
https://github.com/samber/lo.git
synced 2026-04-23 16:40:17 +08:00
1.2 KiB
1.2 KiB
name, slug, sourceRef, category, subCategory, signatures, variantHelpers, similarHelpers, position
| name | slug | sourceRef | category | subCategory | signatures | variantHelpers | similarHelpers | position | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| BufferWithTimeout | bufferwithtimeout | channel.go#L214 | core | channel |
|
|
|
263 |
BufferWithTimeout reads up to size items from a channel with timeout.
ch := make(chan int)
go func() {
time.Sleep(200 * time.Millisecond)
ch <- 1
}()
items, length, readTime, ok := lo.BufferWithTimeout(ch, 5, 100*time.Millisecond)
// Returns empty slice due to timeout
BatchWithTimeout (Deprecated)
BatchWithTimeout is an alias for BufferWithTimeout.
ch := make(chan float64)
go func() {
time.Sleep(150 * time.Millisecond)
ch <- 3.14
}()
batch, length, readTime, ok := lo.BatchWithTimeout(ch, 3, 100*time.Millisecond)
// Returns empty slice due to timeout