-
Notifications
You must be signed in to change notification settings - Fork 24
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
base: main
Are you sure you want to change the base?
Conversation
LGTM could you write tests for this? |
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.
LGTM
@@ -16,25 +14,56 @@ export function throwError( | |||
} | |||
} | |||
|
|||
// deno-lint-ignore no-explicit-any | |||
export async function decodeStream( | |||
export async function decodeStream<T>( |
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.
Nice change, a fan of this
) { | ||
const chunks = res.body! |
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.
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:
- There's an error that we're not catching
- 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!
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 wanna rework this. About the tests. Where should I put them?
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.
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).
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.
Mostly small nits, but definitely a big improvement. Thanks!
) { | ||
const chunks = res.body! |
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.
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) { |
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.
Could you split this off into another PR? Ref: #18
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.
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
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.
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 (;;) { |
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.
for (;;) {
is really dubious to me. Why not while(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.
yeah change that
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.