async.Future.getValue
Returns the settled value (fulfilled or fault value); throws while pending. A pure peek: reading a fault does not acknowledge it (see markHandled)
from "async" import Future
let bounty = Future()
bounty.resolve(100)
println("bounty.getValue() =", bounty.getValue())bounty.getValue() = 100Return 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
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 unhandledpending: Future.getValue: future is still pending
fulfilled: 42
settled null: true
faulted: boomSee also
getState | Returns the lifecycle state: 'pending', 'fulfilled' or 'faulted' |
markHandled | Acknowledges a faulted Future so it is not reported as unhandled; does not consume the value (getValue still reads it) |
resolve | Settles a pending Future with value (default null); ignored if already settled |
| Future | class index |