Closed grundid closed 9 years ago
So after much thought I think we should leave this as is. The main reason is that in some cases, we aren't going to want to call the progress closures on the main thread.
For example, if you have some library that you are working on that handles asset downloads, you probably want Alamofire to call your library off the main thread so you can then handle some processing and then eventually bubble it up to the main thread. If we automatically dispatch the progress closures to the main thread, you'll have to then dispatch again to get off the main thread causing unnecessary dispatching.
The downside of not changing the behavior is that you must dispatch to the main thread if your progress closure needs to update some user interface values. While this is unfortunate, at least you still have full control over the behavior.
Thanks for opening the issue so we could investigate!
Thanks for your reply. May I suggest to update the documentation and maybe add the workaround/solution to update the UI? It took me some time to figure out why the progress view was not updating and how to solve this. We could save this time other developers ;)
+1 for putting this in the documentation!
Absolutely @grundid...I've added a task to our Trello project to get the docs updated before the 2.0 release. I'll update this issue once I've done so. Thanks again.
When uploading a file and using the progress callback the callback method is not called on the main thread. Therefore a progressview is not updated during the upload.
The above code results in the following log output:
progressView created: <NSThread: 0x7f9bf3546160>{number = 1, name = main} encodingCompletion: <NSThread: 0x7f9bf3546160>{number = 1, name = main} Total written 32768 - progress 0.193659 <NSThread: 0x7f9bf5eaf060>{number = 5, name = (null)} Total written 65536 - progress 0.387317 <NSThread: 0x7f9bf370f680>{number = 6, name = (null)} Total written 98304 - progress 0.580976 <NSThread: 0x7f9bf5eaf060>{number = 5, name = (null)} Total written 131028 - progress 0.774374 <NSThread: 0x7f9bf370f680>{number = 6, name = (null)} Total written 131072 - progress 0.774634 <NSThread: 0x7f9bf5e9fe80>{number = 4, name = (null)} Total written 134232 - progress 0.79331 <NSThread: 0x7f9bf370f680>{number = 6, name = (null)} Total written 138516 - progress 0.818628 <NSThread: 0x7f9bf5e9fe80>{number = 4, name = (null)} Total written 141372 - progress 0.835507 <NSThread: 0x7f9bf5eaf060>{number = 5, name = (null)} Total written 144228 - progress 0.852386 <NSThread: 0x7f9bf5e9fe80>{number = 4, name = (null)} Total written 148512 - progress 0.877705 <NSThread: 0x7f9bf3416de0>{number = 7, name = (null)} Total written 151368 - progress 0.894583 <NSThread: 0x7f9bf370f680>{number = 6, name = (null)} Total written 155652 - progress 0.919902 <NSThread: 0x7f9bf370f680>{number = 6, name = (null)} Total written 158508 - progress 0.936781 <NSThread: 0x7f9bf3416de0>{number = 7, name = (null)} Total written 161364 - progress 0.95366 <NSThread: 0x7f9bf5e9fe80>{number = 4, name = (null)} Total written 163840 - progress 0.968293 <NSThread: 0x7f9bf370f680>{number = 6, name = (null)} Total written 168504 - progress 0.995857 <NSThread: 0x7f9bf3416de0>{number = 7, name = (null)} Total written 169205 - progress 1.0 <NSThread: 0x7f9bf5e9fe80>{number = 4, name = (null)}
A workaround for this is to force the update of the progressview on the main thread like this: