Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
入れ子Promise
const wait = true;
const success = false;
const promise2 = new Promise((res, rej) => {
if (success) {
setTimeout(res, 1000, 2)
} else {
rej(3)
}
});
const promise1 = new Promise((res, rej) => {
if (!wait) {
res(1)
} else {
promise2.then(v => res(v)).catch(e => res(e))
}
});
promise1.then(v => console.log(v)).catch(e => console.log(e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment