4 ms·
As a follow-up -- are there any of the authors here? The implementation looks pretty good, but some questions. It looks like you might be using -[NSRunLoop ru
by nupark2 15y ago
As a follow-up -- are there any of the authors here?
The implementation looks pretty good, but some questions.
It looks like you might be using -[NSRunLoop run] to spin a background runloop? That will return immediately if no sources are scheduled in the runloop, which will result in a CPU-heavy busy-waiting thread -- unless I'm missing something here?
I was also wondering about choices like the use of a single statically allocated serial dispatch queue for performing all JSON parsing, rather than using concurrent queues and letting GCD figure out how much concurrency to leverage given the application state and hardware available.
Also, it appears that all callbacks are directly dispatched onto the main thread. Is there any interest in adding support for allowing the caller to specify dispatch onto other queues, in the case that they don't want to hit the main queue for background processing?
- matttthompson 15y agoHey, I'm the primary creator of AFNetworking. - As I understand threading and run loop scheduling, the run loop will spin up as needed when an NSURLConnection attaches itself to it, and back down again when no more connections are active. The dedicated network thread is there only to manage that run loop. - Regarding processing queues, like the JSON one, I thought it would be a good idea to isolate that from the global queue; it could always target another queue if needed. Also, unless I'm mistaken, those queues should be concurrent rather than serial. - As for dispatching to the main thread, this only happens it after all of the work in the operation is done. This just seems like good default behavior. If you wanted to, you could very easily override this by manually setting the `completionBlock` yourself.