Contents

init(newPromiseIn:fromExecutor:)

Creates a promise object using the specified executor callback.

Declaration

init!(newPromiseIn context: JSContext!, fromExecutor callback: ((JSValue?, JSValue?) -> Void)!)

Parameters

  • context:

    The Jscontext the resulting Jsvalue belongs to.

  • callback:

    A callback block to invoke during initialization of the promise object. The resolve and reject parameters are functions that you can call to notify any pending reactions about the state of the new promise object.

Return Value

A JSValue that represents a new promise JavaScript object.

Discussion

This method is equivalent to calling the Promise() constructor in JavaScript.

The resolve and reject callbacks each typically take a single value, which they forward to all relevant pending reactions. While inside the executor callback, context acts as if it is in any other callback, except calleeFunction is nil. This also means you can access the new promise object using [context thisValue].

See Also

Creating JavaScript Values