Skip to content

Instantly share code, notes, and snippets.

@dimpu
Created October 29, 2015 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimpu/7f85b832248f529519a3 to your computer and use it in GitHub Desktop.
Save dimpu/7f85b832248f529519a3 to your computer and use it in GitHub Desktop.
function task(my_task){
return new Promise((resolve,reject)=>{
setTimeout(function(){
if(my_task == 'find loki'){
resolve();
}else{
reject();
}
},2000);
});
}
// this will accept
task('find loki').then(()=>{
console.log("Thor: I'm on it.");
}).catch(()=>{
console.log("Thor: It's my brother I can't do it.");
});
//this will reject
task('kill loki').then(()=>{
console.log("Thor: I'm on it.");
}).catch(()=>{
console.log("Thor: It's my brother I can't do it.");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment