MCPcopy Index your code
hub / github.com/coder/coder / SoftTryReceive

Function SoftTryReceive

testutil/chan.go:70–80  ·  view source on GitHub ↗

SoftTryReceive will attempt to receive a value from the chan and return it. If the context expires before a value can be received, it will mark the test as failed but continue execution. If the channel is closed, the zero value of the channel type will be returned. The second return value indicates

(ctx context.Context, t testing.TB, c <-chan A)

Source from the content-addressed store, hash-verified

68//
69// Safety: can be called from any goroutine.
70func SoftTryReceive[A any](ctx context.Context, t testing.TB, c <-chan A) (A, bool) {
71 t.Helper()
72 select {
73 case <-ctx.Done():
74 assert.Fail(t, "SoftTryReceive: context expired")
75 var a A
76 return a, false
77 case a := <-c:
78 return a, true
79 }
80}
81
82// AssertReceive will receive a value from the chan and return it. If the
83// context expires or the channel is closed before a value can be received,

Callers 1

TestStreamStateCollectorFunction · 0.92

Calls 3

HelperMethod · 0.65
DoneMethod · 0.45
FailMethod · 0.45

Tested by 1

TestStreamStateCollectorFunction · 0.74