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

feat: deserializeAsync parse takes a ReadableStream Uint8Array as input #39

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Sheraff
Copy link
Contributor

@Sheraff Sheraff commented Oct 6, 2023

The goal is to better propagate streaming errors, which happens natively if we use the Response.body stream (might also in the future propagate backpressure).

This has pretty important drawbacks

  • much more opinionated parse function: takes a stream and not any iterator
  • types are lost going through the stream because we're forcing encoding as UInt8Array (this would happen normally through the network though, it's just an issue in the tests I think)
  • we can't just take the output of stringify and pass it to parse (though stringify might also be changed to return a stream instead)

@Sheraff Sheraff self-assigned this Oct 6, 2023
@@ -42,13 +42,22 @@ export function createTsonParseAsyncInner(opts: TsonAsyncOptions) {
}
}

return async (iterable: AsyncIterable<string>) => {
return async (stream: ReadableStream<Uint8Array>) => {
Copy link
Member

@KATT KATT Oct 6, 2023

Choose a reason for hiding this comment

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

maybe

	return async (stream: ReadableStream<Uint8Array> | AsyncIterable<string> | ReadableStream<Uint8Array>) => {

Copy link
Member

Choose a reason for hiding this comment

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

  • we don't care that much about bundle size for this to matter
  • it'd be nicer dx?
  • they can be converted from/to each other seamlessly AFAIK

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.

2 participants