Created
March 9, 2018 20:56
-
-
Save rayning0/9470072a1b59dd610b115e0f5ad4b2a8 to your computer and use it in GitHub Desktop.
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 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