0
votes

I'm using AFNetworking with setting it's built-in operationQueue's maxConcurrentOperationCount value to 1 (Basically I want to dispatch requests serially).

I wonder if a new request will be dequeued from the operation queue before ongoing request's completion block finishes. Will a new request start before calling the completion queue, or will it wait for completion block to finish.

Thanks

1
completionBlock executes as soon as the operation is in its finished state (isFinished == YES). Since an operation queue starts the next operation as soon as the last one finishes, yes—the new operation will start as the completionBlock of the previous one is executing. However, you should not rely on any exact timing with any of that. - mattt
Thanks @mattt, this behavior is what I guessed. In this case, I will have another question. I need to assure that the execution order for my requests' completion blocks would be the same as the enqueue order of the requests to the AFNetworking's operation queue. Because my requests' completion blocks will be called on the main queue (which is the default behavior) and I used maxConcurrentOperationCount =1, I think I can safely assume that previous requirement will hold. Could you verify my hypothesis? - manuyavuz
Yes, that's how queues work. See the NSOperationQueue documentation for the authoritative reference of what they guarantee. - mattt

1 Answers

0
votes

As explained by @mattt in his comment, operation queue used by AFNetworking will start the new request during completionBlock of the previous one is executing. His comment answers my original question.

However, because AFNetworking calls corresponding success/failure blocks of AFHTTPRequestOperation objects inside a concurrent dispatch_queue, currently you can not guarantee completion block call order to be same with request enqueue order even if you use maxConcurrentOperationCount = 1. Details about the issue can be found in here

Thanks to @mattt for the help!