Skip to content

Instantly share code, notes, and snippets.

@jaamaalxyz
Last active January 22, 2019 06:17
Show Gist options
  • Save jaamaalxyz/a77f222e6000bd11efd8d5c010ef36cc to your computer and use it in GitHub Desktop.
Save jaamaalxyz/a77f222e6000bd11efd8d5c010ef36cc to your computer and use it in GitHub Desktop.
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