Skip to content

Correctly handle resolving promises with other promises#1190

Merged
Perryvw merged 2 commits intomasterfrom
promise-bug
Dec 21, 2021
Merged

Correctly handle resolving promises with other promises#1190
Perryvw merged 2 commits intomasterfrom
promise-bug

Conversation

@Perryvw
Copy link
Copy Markdown
Member

@Perryvw Perryvw commented Dec 12, 2021

Fixes #1185

Turns out when resolving a promise with another promise, the other promise is unwrapped. There are three cases here:

  • Resolving promise1 with resolved promise2: resolves promise1 with promise2's value (not promise 2 itself)
  • Resolving promise1 with rejected promise2: rejects promise1 with promise2's rejection reason
  • Resolving promise1 with pending promise2: promise1 will remain pending until promise2 is resolved or rejected
    • promise1 will resolve if promise2 resolves, or reject if promise2 rejects

All of this was verified to match JS behavior on the TypeScript playground

@Perryvw Perryvw requested review from lolleko and tomblind December 12, 2021 19:28
@Perryvw Perryvw merged commit 4bd1872 into master Dec 21, 2021
@Perryvw Perryvw deleted the promise-bug branch December 21, 2021 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Async function returns Promise metatable instead of value

1 participant