Created
March 30, 2018 05:39
-
-
Save chathurawidanage/51db03cccc80a9103aab03c1ba2b2656 to your computer and use it in GitHub Desktop.
Using two callbacks to handle success and failure
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(onSuccess,onError){ | |
//do task | |
if(failed){ | |
onError(error); | |
}else{ | |
onSuccess(data); | |
} | |
} | |
//calling task | |
task((data)=>{ | |
//handle data | |
},(error)=>{ | |
//handle error | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment