Quirrel4.41.0

async.Future.reject

Method of Future, from module "async"
instance.reject([value])

Faults a pending Future with value (default null); ignored if already settled

Parameters

valueanythe value to fault with; null when omitted optional

Errors

Same two guards as resolve: rejecting with itself throws cannot reject a future with itself, and rejecting a task-future throws cannot reject the future returned by an async function.

Notes

Ignored with no error on a future that has already settled - the same idempotency as resolve.

A faulted future that nothing awaits is reported through the unhandled-fault path the next time the host pumps the runtime, the same as an uncaught throw inside an async function. Consume it with await, or acknowledge it with markHandled without consuming it, to stop that report. The call site of reject is captured, so an abandoned future's report carries an ERROR TRACE pointing at where reject was called - unlike a Future faulted from native code, which carries no such trace.

Example

examples/async/future/reject.nut
from "async" import Future

let p = Future()
p.reject("boom")
println("p.getState() =", p.getState())        // faulted
p.reject("ignored")          // no-op: already settled

async function consume(f) {
  try { await f } catch (e) { println("caught:", e) }
}
consume(p)
println("script done")
Output:
p.getState() = faulted
script done
caught: boom

See also

resolveSettles a pending Future with value (default null); ignored if already settled
getValueReturns the settled value (fulfilled or fault value); throws while pending. A pure peek: reading a fault does not acknowledge it (see markHandled)
markHandledAcknowledges a faulted Future so it is not reported as unhandled; does not consume the value (getValue still reads it)
Futureclass index