Back to Lo

Core Bufferwithtimeout

docs/data/core-bufferwithtimeout.md

1.53.0288 B
Original Source

BufferWithTimeout reads up to size items from a channel with timeout.

go
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