Expand description
Racing and timeouts on fibers: Effect::race, race_all, Effect::race_first,
Effect::timeout and Effect::timeout_fail.
Every racer runs as a child fiber of the racing fiber (so the racer’s interruption reaches them, and its exit awaits them). Semantics follow Effect.ts:
race/race_all(Effect.race,Effect.raceAll): the first success wins. The other racers are interrupted and awaited, so their finalizers have run before the result is returned. A failure does not end the race; when every racer fails, the race fails with all the causes combined byCause::Bothin input order (race(a, b)fails withBoth(cause_a, cause_b), like Effect.tsCause.parallel). Effect.tsraceAllkeeps only the last failure; hererace_allkeeps every one, sorace_all([a, b])anda.race(b)agree.race_first(Effect.raceFirst): the first racer to complete wins, success or failure, and the other is interrupted and awaited.timeout(Effect.timeout) israce_firstagainst a sleep on the fiber’s executor clock (virtual time onTestExecutor). The Rust shape returnsOption<A>:Some(a)when the effect finished first,Nonewhen the deadline passed. The Effect.ts 3.xTimeoutExceptionerror channel is the separateEffect::timeout_fail, which fails with an error built by the caller instead. A failure of the effect before the deadline is re-raised as is. Because the interrupted racer is awaited, an uninterruptible (masked) effect delays the timeout until it completes; the result is stillNone.
race_all of no effects dies (as Effect.ts raceAll of an empty iterable does).
Functions§
- race_
all - Races every effect (Effect.ts
Effect.raceAll): the first success wins, and the others are interrupted and awaited (their finalizers have run) before the result is returned. When every effect fails, the race fails with all the causes combined byCause::Bothin input order. An empty input dies.