This repository has been archived by the owner on Jul 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
NSError edited this page Nov 3, 2011
·
3 revisions
One of the (fun) bits of dealing with the API is cross-module data sets, which can introduce situations where you have several requests that can be performed concurrently. NewDot uses NSOperationQueue
to send requests out, and NSOperation
object can handle dependencies. Using this, you can quickly and easily send out concurrent requests without the danger of a deadlock or other nasty bugs caused by race conditions. To do this, simply grab a bunch of NDHTTPURLOperation
s and then wire up the dependencies before sending them off.
In example, the following code will run the FamilyTree and Reservation module properties requests first, and once both have finished the User Profile request will run:
NDService* service = ...;
NDHTTPURLOperation* ftProps =
[service familyTreeOperationPropertiesOnSuccess:^(NSHTTPURLResponse* resp, id response, NSData* payload) { ... }
onFailure:^(NSHTTPURLResponse* resp, NSData* payload, NSError* error) { ... }];
NDHTTPURLOperation* rProps =
[service reservationOperationPropertiesOnSuccess:^(NSHTTPURLResponse* resp, id response, NSData* payload) { ... }
onFailure:^(NSHTTPURLResponse* resp, NSData* payload, NSError* error) { ... }];
NDHTTPURLOperation* uReadReq =
[service familyTreeOperationUserProfileOnSuccess:^(NSHTTPURLResponse* resp, id response, NSData* payload) { ... }
onFailure:^(NSHTTPURLResponse* resp, NSData* payload, NSError* error) { ... }];
[uReadReq addDependency:ftProps];
[uReadReq addDependency:rProps];
[service.operationQueue addOperations:[NSArray arrayWithObjects:ftProps, rProps, uReadReq, nil]
waitUntilFinished:YES];