Gamalto

Fork me on GitHub

Namespace Async Overview

Gamalto. Async

Helper object to handle asynchronous execution.

Extends

Methods

delay(msecs) Promise

static

Wait until the specified time has elasped.

Parameters
Name Type Description
msecs number

Time to wait in millseconds.

Returns
  • Promise to handle wait completion.

Example
var i = 1;

Gamalto.Async.loop(function() {
    gamalto.devel.log("Async.loop()", i);
    if (i++ == 5) {
         return this.delay(2000);
    }
    return (i > 10);

}).then(function() {
    gamalto.devel.log("Done!");
});

immediate() Promise

static

Utility method to handle function execution as soon as possible. It is the counterpart of loop() when no loop is required but a promise is.

Returns
  • Promise to handle function execution.

Example
process([]).then(function() {
    gamalto.devel.log("Done!");
});

function process(data) {
    if (data.length) {
        return Gamalto.Async.loop(function() {
            gamalto.devel.log("Popping:", data.pop());
            return (data.length == 0);
        });
    }
    return Gamalto.Async.immediate();
}

loop(func) Promise

static

Asynchonously loop a function call. Equivalent to a do {...} until(...) statement.

Parameters
Name Type Description
func function

Function to loop.

Returns
  • Promise to handle loop completion.

Example
var i = 1;

Gamalto.Async.loop(function() { // do
    gamalto.devel.log("Async.loop()", i);
    return (i++ == 5); // until

}).then(function() {
    gamalto.devel.log("Done!");
});
Documentation generated by JSDoc 3.3.2 on Sun Sep 13 2015 20:13:31 GMT+0200 (CEST)