MCPcopy
hub / github.com/wavetermdev/waveterm / collectItems

Function collectItems

pkg/utilds/quickreorderqueue_test.go:11–25  ·  view source on GitHub ↗
(ch <-chan T, count int, timeout time.Duration)

Source from the content-addressed store, hash-verified

9)
10
11func collectItems[T any](ch <-chan T, count int, timeout time.Duration) []T {
12 result := make([]T, 0, count)
13 timer := time.NewTimer(timeout)
14 defer timer.Stop()
15
16 for i := 0; i < count; i++ {
17 select {
18 case item := <-ch:
19 result = append(result, item)
20 case <-timer.C:
21 return result
22 }
23 }
24 return result
25}
26
27func TestQuickReorderQueue_InOrder(t *testing.T) {
28 q := MakeQuickReorderQueue[string](10, 100*time.Millisecond)

Calls 1

StopMethod · 0.65

Tested by

no test coverage detected