Last active
January 22, 2019 06:17
-
-
Save jaamaalxyz/a77f222e6000bd11efd8d5c010ef36cc 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
const aPromise = new Promise((resolve, reject) => { | |
setTimeout(() => { | |
if(true) { | |
resolve('I am here!'); | |
} else { | |
reject('No! It is an error!'); | |
} | |
}, 5000) | |
}) | |
// single promises handle | |
aPromiseWithData(false) | |
.then((data) => { | |
console.log(data); | |
}) | |
.catch((err) => { | |
console.log(err); | |
}) | |
// multiple promises handle | |
Promise.all([promise1, promise2]).then((dataArr) => { | |
console.log(dataArr); | |
}) | |
// using fetch api | |
fetch('https://jsonplaceholder.typicode.com/posts') | |
.then((data) => { | |
return data.json(); | |
}).then((posts) => { | |
console.log(posts); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment