async.Future.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
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 onceSee also
getState | Returns the lifecycle state: 'pending', 'fulfilled' or 'faulted' |
resolve | Settles a pending Future with value (default null); ignored if already settled |
reject | Faults a pending Future with value (default null); ignored if already settled |
| Future | class index |