Created
June 7, 2017 11:05
-
-
Save caasi/cefb51765fdbc2b0a56369923d971159 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
const actions = [ | |
() => Promise.resolve(0), | |
() => Promise.resolve(1), | |
() => Promise.reject(new Error('森7')), | |
() => Promise.resolve(3), | |
() => Promise.resolve(new Error('森77')), | |
] | |
const process = () => new Promise((resolve, reject) => { | |
if (actions.length === 0) resolve(true) | |
let f = actions.shift() | |
f().then( | |
r => console.log(r) || resolve(process()), | |
e => reject(e) | |
) | |
}) | |
process() | |
.then( | |
r => console.log('做完了!'), | |
e => console.log(e) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment