I have a method :
-(void) dataForRequest:(NSMutableURLRequest*)url withCallback:(void (^)(NSData* data))callbackBlock`
which gets data from the URL in the background, and then calls the callbackBlock
with the received data.
I'm calling this on a serial queue like :
dispatch_async(my_serial_queue(), ^(void) {
[dataForRequest:SOME_REQUEST withCallback:^(NSData *data) {
// do something with data here.
}];
});
The reason I'm doing this on a serial queue is because i want the requests to get called one at a time, IN ORDER in which they were made.
But the problem I'm facing is, the requests are made in order, but the callbackBlock
that I'm passing to the method is NOT getting called in order.
For e.g., request_1
, request_2
and request_3
are submitted to the serial queue in proper order, but callBackBlock_1
, callBackBlock_2
and callBackBlock_3
are not executed in the same order.
I understand why this is happening, but I am not able to figure out any solution to this. Any help will be appreciated. Thanks!