How are request queues when the underlying infrastructure does not support queuing?

I feel that my question is really n00b; sorry if I don't say this clearly: /

In my project, I use a third-party structure that retrieves some data for me using the asynchronous NSURLRequests (RESTful API). When the data is received and ready, the didReceiveResponse delegate function is didReceiveResponse . In case of an error, didFailWithError is didFailWithError .

The problem is that the infrastructure cannot send requests to the queue, so if I consistently call the request methods, I get only the answer to the last issued request.

Now the problem is that I cannot change the frame code. Given this, is there a workaround for solving this problem? Something like: for a set of requests, request n + 1 is not issued until request n is completed (either didReceiveResponse or didFailWithError ); In addition, when the last request in the set is completed, I receive a kind of notification. Ideally, the solution should be supported for both iOS3 and iOS4.

0
source share
1 answer

It seems your only option is to control the method by which you run queries. To this end, I would distract the idea of ​​the desired request for an object or factory myself: name it Command or SingleRequestFactory or whatever. Hold these objects in an array, and when you get didReceiveResponse or didFailWithError , deactivate the next Command and use it to build the next request that you pass to the third-party structure. If you get didReceiveResponse or didFailWithError and the queue is empty, send a notification.

It is probably best to create an object that executes all this logic on its own, so your view managers / anything that throws these requests can simply point the object to the Command queue without delaying the queue itself.

+2
source

Source: https://habr.com/ru/post/1403350/


All Articles