Last active
March 17, 2016 02:25
-
-
Save davidporter-id-au/228f2cf939916fd08b32 to your computer and use it in GitHub Desktop.
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 makePromise(doSomething){ | |
return new Promise(function(resolve, reject){ | |
doSomething(); | |
resolve("done"); | |
}); | |
} | |
makePromise(function(){ | |
throw "error"; | |
}).then(function(result){ | |
console.log('got result', result); | |
}).catch(function(err){ | |
console.error('got error', err); | |
}); |
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 makePromise(doSomethingAsync){ | |
return new Promise(function(resolve, reject){ | |
doSomethingAsync(resolve); | |
}); | |
} | |
makePromise(function(cb){ | |
setTimeout(function(){ | |
throw "error"; | |
}, 1); | |
}).then(function(result){ | |
console.log('got result', result); | |
}).catch(function(err){ | |
console.error('caught error', err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment