Skip to content

Instantly share code, notes, and snippets.

@k5trismegistus
Created April 18, 2018 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k5trismegistus/7629e4f567c9008a7fc4fdb830b4af8d to your computer and use it in GitHub Desktop.
Save k5trismegistus/7629e4f567c9008a7fc4fdb830b4af8d to your computer and use it in GitHub Desktop.
入れ子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