Skip to main content

Promise

A Promise object represents the eventual completion (or failure) of an asynchronous operation and its resulting value. This allows execution of asynchronous operation in a synchronous fashion by associating handlers to eventual outcomes of the promise. A promise can result in success, rejection, or error. A promise which is not resulted in anything is in pending state.

Members

Properties

NameDescription
Promise.ErrorThe Error message (if there are any) of the promise if it is resulted in Error state.
Promise.ResultThe result of the promise if it is fulfilled and a result expected. Nil otherwise.
Promise.StateState of the current promise.

Methods

NameDescription
Promise.Catch(onError)Associates a handler to be called when promise encounters an error. The Error string will be passed to associated function.
Promise.Then(onFulfill, onRejected=nil)Associate handlers to called when promise if fulfilled or rejected. Note that the promise invokes the associated handlers in the main game thread; therefore, every API can be used safely within handlers.

Extra Detail

Note that the promise invokes the associated handlers in the main game thread; therefore, every API can be used safely within handlers.