{"action":"created","issue":{"url":"https://api.github.com/repos/pinterest/PINRemoteImage/issues/169","repository_url":"https://api.github.com/repos/pinterest/PINRemoteImage","labels_url":"https://api.github.com/repos/pinterest/PINRemoteImage/issues/169/labels{/name}","comments_url":"https://api.github.com/repos/pinterest/PINRemoteImage/issues/169/comments","events_url":"https://api.github.com/repos/pinterest/PINRemoteImage/issues/169/events","html_url":"https://github.com/pinterest/PINRemoteImage/issues/169","id":142481048,"number":169,"title":"Consider calling completion and progress callbacks on the main thread","user":{"login":"DavidNix","id":224251,"avatar_url":"https://avatars.githubusercontent.com/u/224251?v=3","gravatar_id":"","url":"https://api.github.com/users/DavidNix","html_url":"https://github.com/DavidNix","followers_url":"https://api.github.com/users/DavidNix/followers","following_url":"https://api.github.com/users/DavidNix/following{/other_user}","gists_url":"https://api.github.com/users/DavidNix/gists{/gist_id}","starred_url":"https://api.github.com/users/DavidNix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DavidNix/subscriptions","organizations_url":"https://api.github.com/users/DavidNix/orgs","repos_url":"https://api.github.com/users/DavidNix/repos","events_url":"https://api.github.com/users/DavidNix/events{/privacy}","received_events_url":"https://api.github.com/users/DavidNix/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/pinterest/PINRemoteImage/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2016-03-21T21:47:44Z","updated_at":"2016-07-16T10:33:48Z","closed_at":null,"body":"Line of interest:\r\nhttps://github.com/pinterest/PINRemoteImage/blob/7ba1bee59c733f4e11267700e0d4a51f5a177404/Pod/Classes/PINRemoteImageManager.m#L176\r\n\r\nIt's very common for progress and completion callbacks to update UI elements.  Hence, as a library author, calling them on the main thread is typical.  I would even argue best practice.  I admit, I haven't had the time to fully understand the need for calling them on an arbitrary queue (instead of the main queue).  The documentation hints at optimization reasons.\r\n\r\nI spent a good while banging my head because these callbacks were not updating the UI:\r\n```\r\n// From PINRemoteImageManager.h\r\n- (nullable NSUUID *)downloadImageWithURL:(nonnull NSURL *)url\r\n                                  options:(PINRemoteImageManagerDownloadOptions)options\r\n                         progressDownload:(nullable PINRemoteImageManagerProgressDownload)progressDownload\r\n                               completion:(nullable PINRemoteImageManagerImageCompletion)completion;\r\n```\r\n\r\nThen I read the documentation more closely (my fault) and noticed:\r\n> Download or retrieve from cache the image found at the url. All completions are called on an arbitrary callback queue unless called on the main thread and the result is in the memory cache (this is an optimization to allow synchronous results for the UI when an object is cached in memory).\r\n\r\nI was using the progress block to update a progress bar in the UI as well as the completion block to set an image on a UIImageView.\r\n\r\nPerhaps a config option to force callbacks on the main queue?\r\n\r\nThanks for this great library."},"comment":{"url":"https://api.github.com/repos/pinterest/PINRemoteImage/issues/comments/233124241","html_url":"https://github.com/pinterest/PINRemoteImage/issues/169#issuecomment-233124241","issue_url":"https://api.github.com/repos/pinterest/PINRemoteImage/issues/169","id":233124241,"user":{"login":"danielgalasko","id":4479146,"avatar_url":"https://avatars.githubusercontent.com/u/4479146?v=3","gravatar_id":"","url":"https://api.github.com/users/danielgalasko","html_url":"https://github.com/danielgalasko","followers_url":"https://api.github.com/users/danielgalasko/followers","following_url":"https://api.github.com/users/danielgalasko/following{/other_user}","gists_url":"https://api.github.com/users/danielgalasko/gists{/gist_id}","starred_url":"https://api.github.com/users/danielgalasko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielgalasko/subscriptions","organizations_url":"https://api.github.com/users/danielgalasko/orgs","repos_url":"https://api.github.com/users/danielgalasko/repos","events_url":"https://api.github.com/users/danielgalasko/events{/privacy}","received_events_url":"https://api.github.com/users/danielgalasko/received_events","type":"User","site_admin":false},"created_at":"2016-07-16T10:33:48Z","updated_at":"2016-07-16T10:33:48Z","body":"Cool, submitted #222 "}}
{"actor":{"display_login":"danielgalasko"}}