Created
April 18, 2018 03:47
-
-
Save k5trismegistus/7629e4f567c9008a7fc4fdb830b4af8d to your computer and use it in GitHub Desktop.
入れ子Promise
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 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