Created
April 10, 2016 20:33
-
-
Save rauschma/2193594f72a1e92bbacd7747ce8624f9 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
// Demo: converting a thenable to a Promise | |
const fulfilledThenable = { | |
then(reaction) { | |
reaction('hello'); | |
} | |
}; | |
const promise = Promise.resolve(fulfilledThenable); | |
console.log(promise instanceof Promise); // true | |
promise.then(x => console.log(x)); // hello |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Regarding thenables, @bahmutov teached me to start with a promise so you don't have to wrap all library calls with
Promise.resolve()
.instead of