q-ext

1.1.0 • Public • Published

q-ext

NPM version Build Status Coverage Status Dependency Status devDependency Status

What

Methods to extend the Q promise library.

Installation

Via npm, simply run: npm install q-ext

Usage

allSettled(namedPromiseObject) -> Promise

Simply pass an object with named promises. The results are grouped by result (fulfilled/rejected) which can then be spread() into a node-like callback which gives you the errorsByName and resultsByName. NOTE: Unlike traditional node callbacks, the errorsByName object is NEVER undefined (instead being an empty object):

qExt.allSettled({
    aSuccessfulPromise: q.resolve('result'),
    anotherSuccessfulPromise: q.resolve('anotherResult'),
    anUnsuccessfulPromise: q.reject('error'),
    anotherUnsuccessfulPromise: q.reject('anotherError')
}).spread(function (errorsByName, successesByName) {
    console.log('errors:', errorsByName);
    console.log('successes:', successesByName);
}).done();

Passing an array of promises defers to the traditional form:

qExt.allSettled([q.resolve('result'), q.reject('error')]).spread(function (success, error) {
    console.log('success:', success);
    console.log('error:', error);
}).done();

Readme

Keywords

Package Sidebar

Install

npm i q-ext

Weekly Downloads

6

Version

1.1.0

License

Apache 2.0

Last publish

Collaborators

  • daviddenton