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

cancel task before reassigning and don't retain interceptor #1476

Closed
wants to merge 1 commit into from
Closed

cancel task before reassigning and don't retain interceptor #1476

wants to merge 1 commit into from

Conversation

RolandasRazma
Copy link
Contributor

What do you think about such change?
From previous interactions I know you might not like canceling bit, but if we don't cancel currentTask before reassign public func cancel() becomes meaningless

@RolandasRazma RolandasRazma mentioned this pull request Oct 27, 2020
Copy link
Contributor

@designatednerd designatednerd left a comment

Choose a reason for hiding this comment

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

To be clear, it's not that I'm philosophically opposed to cancellation, it's that I think it can sometimes obscure other issues when you do it preemptively when it's not necessary. In this case, it shouldn't really be reassigning, because the interceptor shouldn't be getting reused.

self.currentTask = self.client.sendRequest(urlRequest) { result in
self.currentTask?.cancel()

self.currentTask = self.client.sendRequest(urlRequest) { [weak self] result in
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch on this, I do think this should probably be a [weak self].

@@ -29,7 +29,13 @@ public class NetworkFetchInterceptor: ApolloInterceptor, Cancellable {
return
}

self.currentTask = self.client.sendRequest(urlRequest) { result in
self.currentTask?.cancel()
Copy link
Contributor

Choose a reason for hiding this comment

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

Theoretically this should not be necessary since a new NetworkFetchInterceptor is created for each request chain.

Copy link
Contributor Author

@RolandasRazma RolandasRazma Oct 28, 2020

Choose a reason for hiding this comment

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

since a new NetworkFetchInterceptor is created for each request chain.

This one is interesting, I haven't seen anywhere that this is requirement. When I was migrating at first I just cached all interceptors but then thought that it might be the case that they "have to be new"

Copy link
Contributor

Choose a reason for hiding this comment

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

I added this to the docs on #1484

@designatednerd
Copy link
Contributor

I added the weak self to #1489 - going to close this one out in favor of that. Thank you!

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.

2 participants