-
-
Save lancetw/0b88fced86c96f11ce38b922241284bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, '炸掉啦')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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