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)
| 68 | // |
| 69 | // Safety: can be called from any goroutine. |
| 70 | func 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, |