Skip to content

Instantly share code, notes, and snippets.

@chathurawidanage
Created March 30, 2018 05:39
Show Gist options
  • Save chathurawidanage/51db03cccc80a9103aab03c1ba2b2656 to your computer and use it in GitHub Desktop.
Save chathurawidanage/51db03cccc80a9103aab03c1ba2b2656 to your computer and use it in GitHub Desktop.
Using two callbacks to handle success and failure
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