Created
April 5, 2018 04:41
-
-
Save chathurawidanage/2c176dd5a1fc149a2f53393a75387582 to your computer and use it in GitHub Desktop.
Replacing callbacks with promises
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
function task(){ | |
return new Promise((resolve,reject)=>{ | |
//do task | |
if(failed){ | |
reject(err); | |
}else{ | |
resolve(data); | |
} | |
}); | |
} | |
task().then(data=>{ | |
//handle data | |
}).catch(err=>{ | |
//handle error | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment