Skip to main content
A value that will be available in the future. Use andThen to register callbacks, or await inside async to suspend until the value is ready. Supports cancellation: call cancel() to abort pending work and propagate cancellation to chained promises.

Fields

andThen

Register a callback for when the promise fulfills. The handler may return a value that becomes the next promise’s result.

Constructors

new

Create a new promise with an executor function. The executor receives resolve, reject, and onCancel callbacks.

resolve

Create an already-resolved promise. Resolves with nil if no value given.

reject

Create an already-rejected promise. Error can be any Lua value. Rejects with “rejected” if no argument is provided.

all

Wait for all promises to resolve; rejects if any rejects. On rejection, the remaining promises that nothing else waits on are cancelled.

Methods

catch

Register a callback for when the promise rejects. Errors can be any Lua value (string, table, number, etc.).

finally

Register a callback that runs whether the promise fulfills or rejects.

cancel

Cancel this promise. Fires the onCancel hook (if registered), propagates cancellation down to chained promises, and propagates up to the parent if all its consumers are cancelled. No-op if the promise is already settled.

onCancel

Register a cancellation hook that fires when cancel() is called. Used to clean up in-flight work (e.g. abort a network request). Replaces any hook registered before.

getStatus

Returns the current state: “Pending”, “Fulfilled”, “Rejected”, or “Cancelled”.