-
Notifications
You must be signed in to change notification settings - Fork 437
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
Prevent fetch.pump recursively returning promises #184
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,14 +22,15 @@ class Fetch implements Transport { | |
this.options = transportOptions; | ||
} | ||
|
||
pump(readerArg: ReadableStreamReader, res: Response): Promise<void | Response> { | ||
pump(readerArg: ReadableStreamReader, res: Response) { | ||
this.reader = readerArg; | ||
if (this.cancelled) { | ||
// If the request was cancelled before the first pump then cancel it here | ||
this.options.debug && debug("Fetch.pump.cancel at first pump"); | ||
return this.reader.cancel(); | ||
this.reader.cancel(); | ||
return; | ||
} | ||
return this.reader.read() | ||
this.reader.read() | ||
.then((result: { done: boolean, value: Uint8Array }) => { | ||
if (result.done) { | ||
detach(() => { | ||
|
@@ -40,7 +41,8 @@ class Fetch implements Transport { | |
detach(() => { | ||
this.options.onChunk(result.value); | ||
}); | ||
return this.pump(this.reader, res); | ||
this.pump(this.reader, res); | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this return statement is redundant and can be removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, have removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this caused CI to fail - 'Not all code paths return a value' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh dear that's 2/2 for bad suggestions from me 😂 Apologies for any time wasted and thanks again for the patch |
||
}); | ||
} | ||
|
||
|
@@ -56,7 +58,8 @@ class Fetch implements Transport { | |
this.options.onHeaders(new Metadata(res.headers as any), res.status); | ||
}); | ||
if (res.body) { | ||
return this.pump(res.body.getReader(), res) | ||
this.pump(res.body.getReader(), res) | ||
return; | ||
} | ||
return res; | ||
}).catch(err => { | ||
|
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 explicitaly type the return value, please?
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.
Pump no longer returns anything. The method now matches the send method within the class.
The previously returned promise was never actually used anywhere. The pump method was only called recursively, or from within the
send
method; and send has no return value.All methods within this class that aren't returning anything are missing the
void
return type. I can update them all to void if that's helpful?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.
🤔 Apologies I assumed we had explicit typing.
Given that we do not this boils down to personal preference so feel free to disregard my comment.