Skip to content

Add cancel method for PINRemoteImageManager - #509

Merged
garrettmoon merged 4 commits into
pinterest:masterfrom
zhongwuzw:add_cancel_all_task_method
Jul 11, 2019
Merged

Add cancel method for PINRemoteImageManager#509
garrettmoon merged 4 commits into
pinterest:masterfrom
zhongwuzw:add_cancel_all_task_method

Conversation

@zhongwuzw

Copy link
Copy Markdown
Contributor

Add cancel all tasks for PINRemoteImageManager, it's the convenience method for user to call all tasks one shot, don't need to maintain uuids by themself.

@ghost

ghost commented Jul 8, 2019

Copy link
Copy Markdown

🚫 CI failed with log

@bolsinga

bolsinga commented Jul 9, 2019

Copy link
Copy Markdown
Contributor

Please add tests.

@garrettmoon

Copy link
Copy Markdown
Collaborator

Hmm, I'm not sure this will work. If the UUIDs are stored in a weak hash table, PINRemoteImageManager will 'lose' references to requests that the caller doesn't strongly retain the UUID to…

@zhongwuzw

Copy link
Copy Markdown
Contributor Author

@garrettmoon 🤔 Emm, PINRemoteImageTask would retain UUID by _callbackBlocks.

@zhongwuzw

Copy link
Copy Markdown
Contributor Author

@garrettmoon And I may have a thought to optimize _locked_taskForUUID:key: of PINRemoteManager by add a weak to weak NSMapTable(uuid to task) and exposure key of PINRemoteImageTask, what do you think? 🤔

@garrettmoon

Copy link
Copy Markdown
Collaborator

@garrettmoon 🤔 Emm, PINRemoteImageTask would retain UUID by _callbackBlocks.

You're right! Would you mind adding a comment to the code saying as much?

@garrettmoon

Copy link
Copy Markdown
Collaborator

@garrettmoon And I may have a thought to optimize _locked_taskForUUID:key: of PINRemoteManager by add a weak to weak NSMapTable(uuid to task) and exposure key of PINRemoteImageTask, what do you think? 🤔

Seems like a good optimization because it will also make the code clearer I think!

@zhongwuzw

Copy link
Copy Markdown
Contributor Author

@garrettmoon And I may have a thought to optimize _locked_taskForUUID:key: of PINRemoteManager by add a weak to weak NSMapTable(uuid to task) and exposure key of PINRemoteImageTask, what do you think? 🤔

Seems like a good optimization because it will also make the code clearer I think!

👌 I'll make a PR later~

@garrettmoon garrettmoon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for your contribution here!

}
[task addCallbacksWithCompletionBlock:completion progressImageBlock:progressImage progressDownloadBlock:progressDownload withUUID:UUID];
[self.tasks setObject:task forKey:key];
// Relax :), task retain the UUID for us, it's ok to have a weak reference to UUID here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great comment :)

@garrettmoon
garrettmoon merged commit a5e7ae5 into pinterest:master Jul 11, 2019
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