Skip to content
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

+better stream decoder #16

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Iuriiiii
Copy link

The previous stream decoder got me "chunks is not async iterable" error. I wrote a better Stream Decoder. It ables to cancel the stream whenever you want.

@load1n9
Copy link
Owner

load1n9 commented Jun 13, 2023

LGTM could you write tests for this?

Copy link
Owner

@load1n9 load1n9 left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -16,25 +14,56 @@ export function throwError(
}
}

// deno-lint-ignore no-explicit-any
export async function decodeStream(
export async function decodeStream<T>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice change, a fan of this

@load1n9 load1n9 requested a review from lino-levan June 14, 2023 16:32
) {
const chunks = res.body!
Copy link
Collaborator

Choose a reason for hiding this comment

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

First of all, thank you for the PR, we really appreciate it!

I think my big issue with this PR is the unnecessary complexity it introduces here. If I understand correctly, you have two issues with the current implementation:

  1. There's an error that we're not catching
  2. Wanting to be able to cancel the stream

Both of these can be solved in like ~10 lines of well written code with the current implementation as a base. Reimplementing a stream decoder seems not very useful to me (though I'd love to be proven wrong)!

If you would be willing to rework this PR, please let me know! If not, I will go through and fix these myself. Have a nice day!

Copy link
Author

Choose a reason for hiding this comment

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

I wanna rework this. About the tests. Where should I put them?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't really have tests per se since it's pretty hard to enable testing without using the API (we just use examples right now).

Copy link
Collaborator

@lino-levan lino-levan left a comment

Choose a reason for hiding this comment

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

Mostly small nits, but definitely a big improvement. Thanks!

) {
const chunks = res.body!
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't really have tests per se since it's pretty hard to enable testing without using the API (we just use examples right now).

}
// console.log(data.error);
throw new Error(errorMessage);
export function throwErrorIfNeeded(response: unknown) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you split this off into another PR? Ref: #18

Copy link
Author

Choose a reason for hiding this comment

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

Should we restore the function code and create a new PR with this code and the issue reference?

I don't wanna create a branch from this branch. Should i wait until this be merged?

Sorry, I'm not an expert on github. I don't know the best practices for the prs T-T

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we restore the function code and create a new PR with this code and the issue reference?

Yes, this would be great!

.getReader();

try {
for (;;) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

for (;;) { is really dubious to me. Why not while(true) {?

Copy link
Owner

Choose a reason for hiding this comment

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

yeah change that

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.

None yet

4 participants