Quirrel4.41.0

async.Future.constructor

Method of Future, from module "async"
instance.constructor()

Constructs a pending Future

Errors

Throws Future: constructor called more than once if the constructor runs twice on the same instance - normally unreachable, since a new only ever calls it once, but reachable from a subclass whose own constructor calls base.constructor() more than once.

Notes

A subclass of Future works as long as its constructor chains to base.constructor(). One that skips it leaves the instance without the internal state every other method needs; getState, resolve and the rest then each throw their own ... invalid 'this' error instead of working on a half-built future.

Example

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

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

class Twice(Future) {
  constructor() {
    base.constructor()
    base.constructor()           // constructing twice on the same instance
  }
}
try { Twice() } catch (e) { println("Twice() throws:", e) }
Output:
p.getState() = pending
Twice() throws: Future: constructor called more than once

See also

getStateReturns the lifecycle state: 'pending', 'fulfilled' or 'faulted'
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