Skip to content

Instantly share code, notes, and snippets.

@caasi
Created June 7, 2017 11:05
Show Gist options
  • Save caasi/cefb51765fdbc2b0a56369923d971159 to your computer and use it in GitHub Desktop.
Save caasi/cefb51765fdbc2b0a56369923d971159 to your computer and use it in GitHub Desktop.
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