npm

npm’s 2019 JavaScript ecosystem survey analysis is now available! Get your copy here »

q-promise-utils

1.1.0 • Public • Published

q-promise-utils

Several utils for simpifying interaction with multiple async operations.

API

utils.sequence(funcs, [args])

Executes funcs in async manner one by one. Arguments:

  • funcs - functions to execute
  • args (optional) - arguments to pass to each function

Example:

var foo = function() {},
    bar = function() {};
 
utils.sequence([foo, bar], 'some-string', 100500)
    .then(function() {
        // first executed `foo('some-string', 100500)`,
        // then `bar('some-string', 100500)`,
        // then arrives to this code block
    });

utils.seqMap(items, callback)

Serially applies callback to each item in items array in async manner

Example:

var items = ['foo', 'bar'],
    callback = function() {};
 
utils.seqMap(items, callback)
    .then(function() {
        //first runs `callback` with arg `foo`, then with arg `bar`, next arrives to this code block
    });

utils.waitForResults(promises)

Waits for all promises in array to be resolved or rejected. Unlike Q.allSettled, rejects when any of the promises is rejected. Unlike Q.all does not immediately rejects a promise on a first error and waits for other operations to complete.

Example:

var delay = q.delay(100),
    rejected = q.reject('whatever');
 
utils.waitForResults([rejected, delay])
    .fail(function(reason) {
        //arrives here after 100ms with reject reason `whatever`
    });

install

npm i q-promise-utils

Downloadsweekly downloads

1,338

version

1.1.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability