Created
July 27, 2017 21:08
-
-
Save prof3ssorSt3v3/50c29db2f6e33669c98125f81e02c858 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// ES6 Promises - More syntax and examples | |
// calling resolve directly | |
// calling reject directly | |
// | |
let p1 = new Promise((resolve, reject)=>{ | |
if(true){ | |
resolve('p1 resolved'); | |
}else{ | |
reject('p1 rejected'); | |
} | |
}); | |
let p2 = Promise.resolve('p2 resolved'); | |
let p3 = () => Promise.resolve(null); | |
let p4 = () => Promise.reject('p4 rejected'); | |
p1.then((result)=>{ | |
console.log('p1:', result); | |
}) | |
p2.then((result)=>{ | |
console.log('p2:', result); | |
}); | |
p3().then((result)=>{ | |
console.log('p3:', result); | |
}) | |
p4().then((result)=>{ | |
console.log('Not resolved'); | |
}).catch((result)=>{ | |
console.log('p4 reject: ', result); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment