Created
May 21, 2015 04:12
-
-
Save getify/eb71c7cdc002397f1bea to your computer and use it in GitHub Desktop.
Promises pop quiz: can you articulate the difference(s) between these two snippets?
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 foo() { | |
return new Promise(function(resolve){ | |
mayThrow(); | |
resolve("foo"); | |
}); | |
} |
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 foo() { | |
return Promise.resolve().then(function(){ | |
mayThrow(); | |
return "foo"; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How about:
mayThrow()
runs synchronously in the first but not second. Maybe that's a nit-pick, but I can see how it could trip someone up in certain circumstances.