0

I have 2 fairly simple question. I have 2 mapped requests sent i close succession to each other, called by MAIN thread.

First request: [[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"SomePathToServer"delegate:self]

Second request:

[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"SomeOTHERpathtoServer" delegate:self];

My question is: Are they automatically queued by the object manager?

When i run them now the first request will trigger a rather large syncing communication with the webservice. The second request i fired off in the midst of that communication and is not handled/Recieved by RestKit.

If i run my app again, my code detect that the syncing is done, and now the second request is handled - Data is recieved and mapped.

Do i have to manually add my managed requests to a queue?

I havent found anything about it on the net, so if i have to manually queue it, i wonder if someone has an example or directions to a guide. I have only found queing examples for simple requests, and i have no idea on how to put the First and Second request into the queue - if needed. Help is much appreciated. Thomas

Thomas
  • 75
  • 7
  • RestKit does enqueue requests by default. Do you want to process the requests synchronously? I think the queue allows up to 5 requests to be performed at the same time by default - so you might not even notice the queuing if you have only 2. – mja Oct 30 '11 at 19:22
  • No they do not have to be synchronously. But does restkit then pr. default make asynchronously requests? This is kinda weird, since as described, only the response to the First request is handled, the response to the second request is never detected by restkit. – Thomas Oct 31 '11 at 11:25
  • do you implement RKObjectLoaderDelegate's `- (void)objectLoader:(RKObjectLoader *)objectLoader didFailWithError:(NSError *)error` or `objectLoaderDidLoadUnexpectedResponse:` in case the requests gets stuck somewhere? Did you noticed something unusual in the log? I use the RestKit in one project just like you describe - i start second request before the first one has finished and it works just fine. – mja Oct 31 '11 at 13:25

1 Answers1

2

RKRequestQueue will do the job. You can add to the queue either RKObjectLoader or RKRequest

Here is the example:

RKRequestQueue *queue  =[[RKRequestQueue alloc] init];
    queue.delegate = self;
    queue.concurrentRequestsLimit = 1;
    queue.showsNetworkActivityIndicatorWhenBusy= YES;

    [queue addRequest:[[RKObjectManager sharedManager] objectLoaderWithResourcePath:@"resource" delegate:self]];
    [queue addRequest:[RKClient sharedClient] requestWithResourcePath:@"Another Resource "delegate: self]];

    [queue start];
SunB
  • 142
  • 1
  • 9