Skip to content

Instantly share code, notes, and snippets.

@lancetw
Forked from caasi/promise-sequence.js
Last active June 7, 2017 14:32
Show Gist options
  • Save lancetw/0b88fced86c96f11ce38b922241284bb to your computer and use it in GitHub Desktop.
Save lancetw/0b88fced86c96f11ce38b922241284bb to your computer and use it in GitHub Desktop.
let actions = []
for (let i = 0; i < 10000; i++) {
actions.push(() => Promise.resolve(i))
}
const process = (task) => task.reduce((promised, task) => promised.then(acc => task().then(value => [...acc, value])), Promise.resolve([]))
process(actions)
.then((done) => console.log('做完了!', done))
.catch((err) => console.error(err.message, '炸掉啦'))
let actions = []
for (let i = 0; i < 10000; i++) {
actions.push(() => Promise.resolve(i))
}
const process = (task) => {
let ret = []
return task.reduce((promised, task) => {
return promised.then(task).then(value => {
ret.push(value)
return Promise.resolve(ret)
})
}, Promise.resolve())
}
process(actions)
.then((done) => console.log('做完了!', done))
.catch((err) => console.error(err.message, '炸掉啦'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment