promise-generator
v1.0.0
Published
Promise 顺序执行器
Downloads
8
Readme
Promise generator
Promise 顺序执行(串行执行)器。
安装
$ npm install promise-generator
使用
const pg = require('promise-generator')
const promises = [() => {
return Promise.resolve(0)
}, () => {
return new Promise((resolve) => {
resolve(1)
})
}, () => {
return new Promise((resolve) => {
setTimeout(() => {
resolve(2)
}, 100)
})
}, () => {
return new Promise((resolve) => {
setTimeout(() => {
resolve(3)
}, 100)
})
}, () => {
return new Promise((resolve) => {
setTimeout(() => {
resolve(4)
}, 100)
})
}]
pg(promises).then((data) => {
console.log(data); // 300ms+之后输出:[0,1,2,3,4]
})
贡献
欢迎大家提issue、fork;有任何疑问也可以邮件联系:xiongwilee[at]foxmail.com。