Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including q-promise-utils with all npm packages installed. Try it out:

var qPromiseUtils = require("q-promise-utils")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

q-promise-utils v1.1.0

Several promise helpers simplifying interaction with multiple async operations


Several utils for simpifying interaction with multiple async operations.


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


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


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


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.


var delay = q.delay(100),
    rejected = q.reject('whatever');

utils.waitForResults([rejected, delay])
    .fail(function(reason) {
        //arrives here after 100ms with reject reason `whatever`
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free