-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: deal with fast consecutive promise resolutions when streaming #9332
Conversation
next: async () => { | ||
const next = await deferred[0].promise; | ||
if (!next.done) deferred.shift(); | ||
return next; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
next: async () => { | |
const next = await deferred[0].promise; | |
if (!next.done) deferred.shift(); | |
return next; | |
} | |
next: deferred.shift().promise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a type cast because TS doesn't know this is always defined, and strictly speaking it's not adhering to the spec that says you can call next
as much as you want after it's done (it should always return done: true
in that state).
}; | ||
} | ||
}, | ||
push: (value) => { | ||
deferred.fulfil({ value, done: false }); | ||
deferred = defer(); | ||
deferred[deferred.length - 1].fulfil({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deferred[deferred.length - 1].fulfil({ | |
deferred.at(-1).fulfil({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment below
}, | ||
done: () => { | ||
deferred.fulfil({ done: true }); | ||
deferred[deferred.length - 1].fulfil({ done: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deferred[deferred.length - 1].fulfil({ done: true }); | |
deferred.at(-1).fulfil({ done: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had that previously but that requires you to do a stupid type cast because TS says "this might be undefined" and that code was harder to read/longer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait TS thinks array.at(x)
might be undefined but array[x]
is not? the fuck?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is mostly due to backwards compatibility to not break existing code bases. They have another flag outside the strict
family that turns on the same behavior for array[x]
fixes #9330
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.