Files
lo/docs/data/core-bufferwithtimeout.md
T
2026-02-22 05:20:42 +01:00

769 B

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
func BufferWithTimeout[T any](ch <-chan T, size int, timeout time.Duration) (collection []T, length int, readTime time.Duration, ok bool)
core#channel#bufferwithtimeout
core#channel#buffer
core#channel#bufferwithcontext
core#channel#slicetochannel
core#channel#channeltoslice
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