Skip to content

Instantly share code, notes, and snippets.

@abel-masila
Created April 24, 2018 14:10
Show Gist options
  • Save abel-masila/1b326858f50e4889294adcd7c42a8872 to your computer and use it in GitHub Desktop.
Save abel-masila/1b326858f50e4889294adcd7c42a8872 to your computer and use it in GitHub Desktop.
//async promise with user input
const asyncAdd=(a,b)=>{
return new Promise((resolve,reject)=>{
setTimeout(()=>{
if(typeof a=== 'number' && typeof b==='number'){
resolve(a+b);
}else {
reject('Arguments must be numbers');
}
},1500)
})
}
asyncAdd(9,7).then((res)=>{
console.log("Result: " , res);
return asyncAdd(res, 33);
}).then((res)=>{
console.log("New sum: ", res);
}).catch((errorMessage)=>{
console.log(errorMessage);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment