Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AFNetworking: Dispatching a concurrent queue and running synchronous tasks within that

I am using AFNetworking in an app I am developing. For downloading requests, I am ussing AFHTTPRequestOperation's setCompletionBlockWithSuccess:failure. This ties a success block and and a failure block to an operation, and the operation is then added to an NSOperationQueue using addOperation.

AFNetworking creates an asynchronous thread and runs all the data there. However, I'd like to add three operations to a concurrent thread, whereby they run synchronously. Also known as a serial queue in GCD. How can I achieve that in AFNetworking? Should I create my own serial queue and then addOperation in that queue, moving all the request initialization, success block, failure block and adding under the serial queue?

like image 315
darksky Avatar asked Dec 16 '25 22:12

darksky


1 Answers

Setting the NSOperationQueue maxConcurrentOperationCount property to 1 effectively creates a serial queue. You can then be assured each request will complete before the next operation is triggered.

like image 122
Mike Fahy Avatar answered Dec 19 '25 14:12

Mike Fahy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!