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)
| 14 | // |
| 15 | // Safety: Must only be called from the Go routine that created `t`. |
| 16 | func 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, |