1.0.2 • Published 4 years ago
@pushstack/promise v1.0.2
sopromise
A sample implementation of Promises/A+.
Usage
npm i sopromise
Example:
import Promise from 'sopromise';
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
License
1.0.2
4 years ago