Async.Promise library

.html ›› .html ›› .html ››
Parent Previous Next

Async.Promise library

The Async.Promise library provides functions for handling asynchronous operations, such as loading a remote node database. All of these functions are contained in the “Async.Promise” and/or “Promise” Lua tables found in the “async.lua” unit.


Usage example:

-- First, you need to require the “async.lua” unit
require("async.lua");   

-- Now you can access the functions of the library.
Async.Promise.LIBRARY_FUNCTION(Argument1, Argument2, ...);
or
Promise.LIBRARY_FUNCTION(Argument1, Argument2, ...);



Async.Promise library functions


function Async.Promise.all(promise1[, promise2[, promise3[, ... promiseN]]])
function Async.Promise.all(promisesArray)
function Promise.all(promise1[, promise2[, promise3[, ...promiseN]]])
function Promise.all(promisesArray)


This function takes a set of Promise objects and creates a single Promise object that will be resolved when all provided promises are resolved. The set of Promise objects can be passed to this function using one of the following styles:


Arguments (variable number of arguments style):


Arguments (array style):


Return:


Remarks:



function Async.Promise.isPromise(value)
function Promise.isPromise(value)


Check is the provided value is a Promise object


Arguments:


Return:

function Async.Promise.resolved(data)
function Async.Promise.resolve(data)
function Async.Promise.succeeded(data)
function Promise.resolved(data)
function Promise.resolve(data)
function Promise.succeeded(data)


Creates and returns a Promise object that has already been successfully resolved with the provided “data” argument


Arguments:


Return:


function Async.Promise.toHandle(promise, successCallback,[, failureCallback])
function Promise.toHandle(promise, successCallback[, failureCallback])


Creates a Promise object that receives the outcome of another existing Promise object and potentially returns converted data.


Arguments:


Return:


Remarks



function Async.Promise.toResolve()
function Async.Promise.pending()
function Promise.toResolve()
function Promise.pending()


Creates a Promise object that is in a pending state and its associated Promise Resolution object.


This function returns 2 values:


Remarks



function Async.Promise.withError(errorMsg)
function Async.Promise.withException(errorMsg)
function Async.Promise.failed(errorMsg)function Async.Promise.reject(errorMsg)
function Promise.withError(errorMsg)
function Promise.withException(errorMsg)
function Promise.failed(errorMsg)
function Promise.reject(errorMsg)


Creates and returns a Promise object that has already been resolved with a failure state and with the provided error message


Arguments:


Return:

Created with the Personal Edition of HelpNDoc: Eliminate the Struggles of Documentation with a Help Authoring Tool