Skip to content

Instantly share code, notes, and snippets.

@rayning0
Created March 9, 2018 20:56
Show Gist options
  • Save rayning0/9470072a1b59dd610b115e0f5ad4b2a8 to your computer and use it in GitHub Desktop.
Save rayning0/9470072a1b59dd610b115e0f5ad4b2a8 to your computer and use it in GitHub Desktop.
const myfunc = (add1, add2) => {
return new Promise((resolve, reject) => {
const new_value = add1 + add2;
setTimeout(() => {
resolve(new_value);
}, 3000);
})
};
myfunc(1, 5)
.then((added_value) => {
console.log(`the value is ${added_value}`);
})
.catch((err) => {
console.error(`there was an error ${err}`);
});
//-------------------------------
const myfunc = (add1, add2) => {
return new Promise((resolve, reject) => {
const new_value = add1 + add2;
setTimeout(() => {
console.log(`new value ${new_value}`);
resolve(new_value);
}, 3000);
})
};
const mypromises = [
myfunc(1, 5),
myfunc(6, 5),
myfunc(2, 9),
myfunc(10, 5),
];
Promise.all(mypromises)
.then(() => {
console.log('they all resolved');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment