Quirrel4.41.0

async.Future.getValue

Method of Future, from module "async"
instance.getValue(): any

Returns the settled value (fulfilled or fault value); throws while pending. A pure peek: reading a fault does not acknowledge it (see markHandled)

examples/async/future/getValue-basic.nut
from "async" import Future

let bounty = Future()
bounty.resolve(100)

println("bounty.getValue() =", bounty.getValue())
Output:
bounty.getValue() = 100

Return value

Whatever the future settled with, verbatim - the fault value on a faulted future, not the fault re-raised as an error.

Errors

Throws Future.getValue: future is still pending while the future has not settled yet, so null can stay a valid settled value: check getState first if null would otherwise be ambiguous.

Notes

This is the synchronous read; await is the asynchronous one, and unlike getValue, await re-raises a fault instead of returning it.

getValue is a pure peek: reading a faulted future's value this way does NOT acknowledge the fault, so an otherwise-unconsumed fault still reports as unhandled. Take responsibility for it with markHandled, or consume it with await.

Example

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

let p = Future()
try { p.getValue() } catch (e) { println("pending:", e) }

let f = Future(); f.resolve(42)
println("fulfilled:", f.getValue())

let n = Future(); n.resolve(null)
println("settled null:", (n.getState() == "fulfilled" && n.getValue() == null))

let r = Future(); r.reject("boom")
println("faulted:", r.getValue())   // a pure peek: does not acknowledge the fault
r.markHandled()                        // ack, so it is not reported as unhandled
Output:
pending: Future.getValue: future is still pending
fulfilled: 42
settled null: true
faulted: boom

See also

getStateReturns the lifecycle state: 'pending', 'fulfilled' or 'faulted'
markHandledAcknowledges a faulted Future so it is not reported as unhandled; does not consume the value (getValue still reads it)
resolveSettles a pending Future with value (default null); ignored if already settled
Futureclass index