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

Prevent fetch.pump recursively returning promises #184

Conversation

nathanb21
Copy link
Contributor

@nathanb21 nathanb21 commented Apr 29, 2018

Fixes #183

Before:
image

After:
image

@jonnyreeves
Copy link
Contributor

Thanks for this patch, please could you include a screenshot of the chrome memory profiler which demonstrates the new characteristics with this change.

Copy link
Contributor

@jonnyreeves jonnyreeves left a comment

Choose a reason for hiding this comment

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

Small nitpicking otherwise LGTM. Thanks for contributing

@@ -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;
Copy link
Contributor

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?

Copy link
Contributor Author

@nathanb21 nathanb21 Apr 29, 2018

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

All methods within this class that aren't returning anything are missing the void return type

🤔 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.

@@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this return statement is redundant and can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, have removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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'

Copy link
Contributor

Choose a reason for hiding this comment

The 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

@nathanb21
Copy link
Contributor Author

@jonnyreeves added screenshots taken from issue 183. Thanks for your feedback 👍

@nathanb21 nathanb21 force-pushed the bugfix/prevent-fetch-pump-promise-recursion branch from ffd0827 to 5d56a6e Compare April 30, 2018 06:12
@jonnyreeves
Copy link
Contributor

Good to merge. Will aim to action this and cut a release to npm either today or tomorrow, schedule permitting. Thanks again

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.

3 participants