Created
October 29, 2015 08:43
-
-
Save dimpu/7f85b832248f529519a3 to your computer and use it in GitHub Desktop.
This file contains 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(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