Quirrel4.41.0

async.Future.getState

Method of Future, from module "async"
instance.getState(): string

Returns the lifecycle state: 'pending', 'fulfilled' or 'faulted'

Return value

One of the strings "pending", "fulfilled" or "faulted".

Notes

State only moves forward, and only once: pending to fulfilled or pending to faulted. Once settled, a future stays in that state for the rest of its life; a later resolve or reject call is a silent no-op and does not change what getState reports.

Example

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

let p = Future()
println("p.getState() =", p.getState())    // pending
p.resolve(1)
println("p.getState() =", p.getState())    // fulfilled

let q = Future()
q.reject("boom")
println("q.getState() =", q.getState())    // faulted
q.markHandled()          // ack so the fault is not reported as unhandled
Output:
p.getState() = pending
p.getState() = fulfilled
q.getState() = faulted

See also

getValueReturns the settled value (fulfilled or fault value); throws while pending. A pure peek: reading a fault does not acknowledge it (see markHandled)
resolveSettles a pending Future with value (default null); ignored if already settled
rejectFaults a pending Future with value (default null); ignored if already settled
Futureclass index