Skip to content

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

Closed
RolandasRazma wants to merge 1 commit intoapollographql:mainfrom
getfiit:NetworkFetchInterceptor_no_retain
Closed

cancel task before reassigning and don't retain interceptor#1476
RolandasRazma wants to merge 1 commit intoapollographql:mainfrom
getfiit:NetworkFetchInterceptor_no_retain

Conversation

@RolandasRazma
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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].

}

self.currentTask = self.client.sendRequest(urlRequest) { result in
self.currentTask?.cancel()
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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