Created
April 24, 2018 14:10
-
-
Save abel-masila/1b326858f50e4889294adcd7c42a8872 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
//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