BlockWithTimeout implements context.Context.BlockWithTimeout. Preconditions: The caller must be running on the task goroutine.
(C chan struct{}, haveTimeout bool, timeout time.Duration)
| 29 | // |
| 30 | // Preconditions: The caller must be running on the task goroutine. |
| 31 | func (t *Task) BlockWithTimeout(C chan struct{}, haveTimeout bool, timeout time.Duration) (time.Duration, error) { |
| 32 | if !haveTimeout { |
| 33 | return timeout, t.block(C, nil) |
| 34 | } |
| 35 | |
| 36 | clock := t.Kernel().MonotonicClock() |
| 37 | start := clock.Now() |
| 38 | deadline := start.Add(timeout) |
| 39 | err := t.blockWithDeadlineFromSampledClock(C, clock, deadline) |
| 40 | |
| 41 | // Timeout, explicitly return a remaining duration of 0. |
| 42 | if linuxerr.Equals(linuxerr.ETIMEDOUT, err) { |
| 43 | return 0, err |
| 44 | } |
| 45 | |
| 46 | // Compute the remaining timeout. Note that even if block() above didn't |
| 47 | // return due to a timeout, we may have used up any of the remaining time |
| 48 | // since then. We cap the remaining timeout to 0 to make it easier to |
| 49 | // directly use the returned duration. |
| 50 | end := clock.Now() |
| 51 | remainingTimeout := timeout - end.Sub(start) |
| 52 | if remainingTimeout < 0 { |
| 53 | remainingTimeout = 0 |
| 54 | } |
| 55 | |
| 56 | return remainingTimeout, err |
| 57 | } |
| 58 | |
| 59 | // BlockWithTimeoutOn implements context.Context.BlockWithTimeoutOn. |
| 60 | // |
no test coverage detected