Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lensh/mini-promise
Mini version promise based on promise a + specification supports asynchronous chain call.
https://github.com/lensh/mini-promise
promise
Last synced: 4 days ago
JSON representation
Mini version promise based on promise a + specification supports asynchronous chain call.
- Host: GitHub
- URL: https://github.com/lensh/mini-promise
- Owner: lensh
- Created: 2019-12-11T17:35:56.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-12-11T17:38:16.000Z (about 5 years ago)
- Last Synced: 2024-11-09T05:38:53.150Z (about 2 months ago)
- Topics: promise
- Language: JavaScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## MyPromise
Mini version promise based on promise a + specification supports asynchronous chain call.
## Support
* new MyPromise
* MyPromise.prototype.then
* MyPromise.prototype.catch
* MyPromise.all
* MyPromise.race
* MyPromise.resolve
* MyPromise.reject
## Usage
```js
import 'colors'
import { MyPromise } from '../lib/MyPromise'const log = console.log
// test asynchronous chain call promsie
let p = new MyPromise((res, rej) => {
setTimeout(() => {
res(1)
}, 600)
}).then(ret1 => {
log('then1:'.green, ret1)
return MyPromise.resolve(2)
}).then().then(ret2 => {
log('then2:'.magenta, ret2)
})// generate a promise array
let arr = [1, 2, 3, 4, 5].map((t, i) => {
return new MyPromise((res, rej) => {
setTimeout(() => {
res(t)
}, i * 1000)
})
})
// test promise.all
MyPromise.all(arr).then(ret => {
log('promise.all'.rainbow, ret)
})
// test promise.race
MyPromise.race(arr).then(ret => {
log('promise.race'.yellow, ret)
})// test promise.resolve
let p1 = MyPromise.resolve(2)
p1.then(ret => {
log('promsie.resolve'.cyan, ret)
})// test promise.reject
let p2 = MyPromise.reject(3)
p2.catch(e => {
log('promsie.reject'.red, e)
})
```