1.0.1 • Published 6 years ago
@walkerbe/promiser v1.0.1
Promiser
A sample implementation of Promises/A+.
Usage
npm i @walkerbe/promiser
Example:
import Promise from '@walkerbe/promiser';
let p1 = function () {
return new Promise((resolve, reject) => {
setTimeout(function () {
resolve('hello Promise');
}, 1000);
});
};
p1().then((res) => {
console.log('res: ', res);
}, (error) => {
console.log('error: ', error);
}).catch((error) => {
console.log('error finally: ', error);
});
// res: hello Promise
// with async await
async function asyncTest() {
let res = await p1();
console.log('async function result: ', res);
}
asyncTest();
// async function result: hello Promise
Include Methods
- Promise.prototype.then()
- Promise.prototype.catch()
- Promise.prototype.finally()
- Promise.resolve()
- Promise.reject()
- Promise.all()
- Promise.race()
Test
Use promises-aplus-tests to test.
npm run test
Todos
- implement Promises/A+
- use rollup to build
- add methods:
resolve
,reject
,all
,race
,finally