Skip to content

Commit

Permalink
🐛 Use then instead of finally for promises with the yieldTo util (#1016)
Browse files Browse the repository at this point in the history
Some versions of V8 complain about promise rejections if there is no detected catch handler. Even
though we await on these promises and allow them to reject asynchronously, the error can still
surface as "PromiseRejectionHandledWarning: Promise rejection was handled asynchronously."

This is fixed by using then with a catch handler instead of a single finally. The promise reference
no longer needs to be updated since it would cause issues to be swallowed.
  • Loading branch information
wwilsman authored Jul 29, 2022
1 parent 012892c commit 0b85c22
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class AbortError extends Error {
// An async generator that yields after every event loop until the promise settles
export async function* yieldTo(subject) {
let pending = typeof subject?.finally === 'function';
if (pending) subject = subject.finally(() => (pending = false));
if (pending) subject.then(() => (pending = false), () => (pending = false));
/* eslint-disable-next-line no-unmodified-loop-condition */
while (pending) yield new Promise(r => setImmediate(r));
return isGenerator(subject) ? yield* subject : await subject;
Expand Down

0 comments on commit 0b85c22

Please sign in to comment.