Skip to content

Promise ​

Async results for async / await.

Always available

No import needed. These names are in scope in every file.

Promise class ​

ts
class Promise<T>

Final: it cannot be subclassed.

Async result of a deferred computation. State is one of pending, fulfilled, or rejected; transitions are one-way. Handler chains run via the microtask queue.

Promise.then ​

ts
then(onFulfilled?: Function, onRejected?: Function): Promise<any>

Attach fulfillment and rejection handlers. Returns a new promise that resolves to the handler's return value (or rejects with a thrown value). Either handler may be omitted to pass the settlement through unchanged.

Promise.catch ​

ts
catch(onRejected?: Function): Promise<any>

Shorthand for then(undefined, onRejected).

Promise.finally ​

ts
finally(onFinally?: Function): Promise<T>

Run onFinally after the promise settles, regardless of outcome. The returned promise mirrors the receiver's state; onFinally cannot observe or alter the resolution value.

Promise.all ​

ts
static all(iterable: Array<any>): Promise<Array<any>>

Resolve when every input settles fulfilled, or reject on the first rejection. Inputs may be promises or plain values; plain values are wrapped via Promise.resolve. Resolves with an array of fulfilled values in input order.

Promise.allSettled ​

ts
static allSettled(iterable: Array<any>): Promise<Array<SettledResult>>

Resolve when every input settles, regardless of outcome. Resolves with an array of SettledResult records in input order.

Promise.any ​

ts
static any(iterable: Array<any>): Promise<any>

Resolve on the first input to fulfil, or reject when every input has rejected. The aggregate rejection is reported as an AggregateError-shaped string today; the typed AggregateError class is registered separately.

Promise.race ​

ts
static race(iterable: Array<any>): Promise<any>

Resolve or reject as soon as any input settles, mirroring its outcome. Subsequent settlements are ignored.

Promise.reject ​

ts
static reject(reason?: any): Promise<any>

Return a promise rejected with reason. Already-rejected promises pass through unchanged.

Promise.resolve ​

ts
static resolve(value: Promise<any>): Promise<any>
static resolve<T>(value?: T): Promise<T>

Return a promise fulfilled with value. Already-fulfilled promises pass through unchanged.

Two signatures, because the result's type argument is the ARGUMENT's type and a promise argument is flattened rather than nested. The promise overload is declared first so it wins for a promise argument; T binds from anything else.

Example

ts
const value: string = await Promise.resolve("ready");
console.log(value); // ready

SettledResult class ​

ts
class SettledResult

Type only: the runtime hands you instances; you never construct it yourself.

Per-entry record produced by Promise.allSettled. status is "fulfilled" or "rejected". Fulfilled records carry value; rejected records carry reason. The other field is absent.

ts
readonly status: string
readonly value?: any
readonly reason?: any

Generated from lang/types/builtin_async.d.tks in the ThicketScript repository.