q-promise

promise polyfill with add-ons

MIT 17 个版本
安装
npm install q-promise
yarn add q-promise
pnpm add q-promise
bun add q-promise
README

q-promise

travis Build Status Wercker wercker status

Full Promises/A+ compliance

Installation

npm install q-promise --save

# alternatively you can use bower (minified version by default)
bower install q-promise --save

ES6 Promise

// q-promise respects the es6 promise specification
// you can use q-promise as global polyfill

if( !window.Promise ) {
  window.Promise = $q;
}

Example

$q(function (resolve, reject) {
        resolve('gogogo!');
    })

    .then(function (result) {
        console.log('checkpoint 1', result);
        throw 'whoops!';
    })

    .then(function (result) {
        console.log('checkpoint 2', result);
    },function (result) {
        console.log('checkpoint 2.1', result);
        return qPromise(function (resolve, reject) {
            setTimeout(function () { resolve('all right!'); }, 400);
        });
    })

    .then(function (result) {
        console.log('checkpoint 3', result);
    }, function (reason) {
        console.log('checkpoint 3.1', reason);
    })
;

output:

checkpoint 1 gogogo!
checkpoint 2.1 whoops!
# elapsed 400ms
checkpoint 3 all right!

Tests

make test
版本列表
1.0.0 2016-12-09
0.3.7 2016-09-26
0.3.6 2016-09-26
0.3.5 2016-08-30
0.3.4 2016-08-30
0.3.3 2016-08-30
0.3.2 2016-06-23
0.3.1 2016-06-23
0.3.0 2016-06-23
0.2.6 2016-04-08
0.2.5 2016-04-08
0.2.4 2016-04-08
0.2.3 2016-04-08
0.2.2 2016-04-08
0.2.1 2016-01-12
0.1.2 2016-01-12
0.1.1 2016-01-12