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

Function TryReceive

testutil/chan.go:16–26  ·  view source on GitHub ↗

TryReceive will attempt to receive a value from the chan and return it. If the context expires before a value can be received, it will fail the test. If the channel is closed, the zero value of the channel type will be returned. Safety: Must only be called from the Go routine that created `t`.

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

Source from the content-addressed store, hash-verified

14//
15// Safety: Must only be called from the Go routine that created `t`.
16func TryReceive[A any](ctx context.Context, t testing.TB, c <-chan A) A {
17 t.Helper()
18 select {
19 case <-ctx.Done():
20 require.Fail(t, "TryReceive: context expired")
21 var a A
22 return a
23 case a := <-c:
24 return a
25 }
26}
27
28// RequireReceive will receive a value from the chan and return it. If the
29// context expires or the channel is closed before a value can be received,

Calls 3

HelperMethod · 0.65
DoneMethod · 0.45
FailMethod · 0.45