marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
3.01k stars 795 forks source link

Ch 11, Promises section: immediately finishes #398

Closed dhollinden closed 6 years ago

dhollinden commented 6 years ago

In this paragraph:

"The easiest way to create a promise is by calling Promise.resolve. This function ensures that the value you give it is wrapped in a promise. If it’s already a promise it is simply returned, and otherwise you get a new promise that immediately finishes with your value as its result."

I'm confused by what's implied by "immediately finishes" here, since further down the text states that a promised value "might appear at some point in the future."

Thanks

marijnh commented 6 years ago

Yes, it might, but if you give Promise.resolve a plain value it won't, since there's nothing to wait for, which is why it is described this way.