Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.

Conversation

@Sheraff
Copy link
Contributor

@Sheraff Sheraff commented Oct 6, 2023

deserializeAsync uses a ReadableStream for each of the async values. This allows for

  • calling controller.enqueue to add values (single value for Promise, as many values as we want for AsyncIterator)
  • calling controller.close from anywhere without needing an onDone callback
  • back/forward pressure (this might need some testing / tweaking)
  • error handling (this might need some testing / tweaking)

@Sheraff Sheraff self-assigned this Oct 6, 2023
@Sheraff Sheraff changed the title feat: deserializeAsync uses streams to pipe values feat: deserializeAsync uses streams to pipe values Oct 6, 2023
@codecov
Copy link

codecov bot commented Oct 6, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Files Coverage Δ
src/async/asyncTypes.ts 100.00% <100.00%> (ø)
src/async/deserializeAsync.ts 99.08% <100.00%> (-0.18%) ⬇️
src/handlers/tsonPromise.ts 94.91% <100.00%> (+0.08%) ⬆️
src/handlers/tsonAsyncIterable.ts 88.33% <71.42%> (-0.38%) ⬇️

📢 Thoughts on this report? Let us know!.

@Sheraff Sheraff requested a review from KATT October 6, 2023 09:45
Comment on lines +192 to +193
for (const controller of cache.values()) {
controller.error(err);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you call .error() after it's closed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.error yes I believe, this method just makes it so that any future interaction with the stream will error, it is not an error by itself.

return;
}
let next: ReadableStreamReadResult<SerializedIteratorResult>;
while (((next = await opts.reader.read()), !next.done)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could prob be prettier :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, while(true) and if(next.done) return would have worked fine, but then eslint doesn't like while(true) so I went with this. We can eslint-disable-next-line instead if you prefer.

Comment on lines +34 to +37
case ITERATOR_ERROR: {
opts.controller.close();
throw TsonPromiseRejectionError.from(next.value[1]);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we need to test this with that warning

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we need to add tests for

  • tsonAsyncIterable
  • more weird cases for deserializeAsync to make sure everything errors and closes correctly

Base automatically changed from fix/deserialize-async/arbitrary-chunks to main October 6, 2023 09:55
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Compliance Checks

Thank you for your Pull Request! We have run several checks on this pull request in order to make sure it's suitable for merging into this project. The results are listed in the following section.

Issue Reference

In order to be considered for merging, the pull request description must refer to a specific issue number. This is described in our Contributing Guide. We are closing this pull request for now but you can update the pull request description and reopen the pull request.
The check is looking for a phrase similar to: "Fixes #XYZ" or "Resolves #XYZ" where XYZ is the issue number that this PR is meant to address.

@KATT KATT enabled auto-merge (squash) October 6, 2023 09:56
@KATT KATT merged commit 0363707 into main Oct 6, 2023
@KATT KATT deleted the feat/deserialize-async/use-streams-to-pipe-values branch October 6, 2023 09:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants