AFNetworking/AFNetworking — pull request #154 by mattt (2011-12-18 06:00:35+00:00)
Title: Add Support for Batched HTTP Request Operations

This pull request adds the following methods to `AFHTTPClient`:

``` objective-c
- (void)enqueueBatchOfHTTPRequestOperationsWithRequests:(NSArray *)requests
progressBlock:(void (^)(NSUInteger numberOfCompletedOperations, NSUInteger totalNumberOfOperations))progressBlock
completionBlock:(void (^)(NSArray *operations))completionBlock;

- (void)enqueueBatchOfHTTPRequestOperations:(NSArray *)operations
progressBlock:(void (^)(NSUInteger numberOfCompletedOperations, NSUInteger totalNumberOfOperations))progressBlock
completionBlock:(void (^)(NSArray *operations))completionBlock;
```

With these methods, you can now easily batch separate but related operations in such a way to be updated on their completion individually, as well as collectively. Users moving over from ASIHTTPRequest noted missing this feature, which in ASI was implemented with a custom operation queue.

This would be particularly useful, for instance, when doing a batch upload of several files, so that the app could display a progress meter as each file completes, dismissing the dialog when everything is finished. This would likewise be useful for multi-get operations, where the display of a screen would not be possible until all of a set of requests has finished loading.

Here is a simple example to demonstrate the feature in action:

``` objective-c
NSMutableArray *mutableRequests = [NSMutableArray array];
for (NSString *URLString in [NSArray arrayWithObjects:@"/spots/11514", @"/spots/11507", @"/spots/11515", nil]) {
[mutableRequests addObject:[[AFGowallaAPIClient sharedClient] requestWithMethod:@"GET" path:URLString parameters:nil]];
}

[[AFGowallaAPIClient sharedClient] enqueueBatchOfHTTPRequestOperationsWithRequests:mutableRequests progressBlock:^(NSUInteger numberOfCompletedOperations, NSUInteger totalNumberOfOperations) {
NSLog(@"%lu of %lu Completed", numberOfCompletedOperations, totalNumberOfOperations);
} completionBlock:^(NSArray *operations) {
NSLog(@"Completion: %@", operations);
}];
```

Any thoughts about this feature would be greatly appreciated—especially if you can share some insight into how this stacks up against the aforementioned corollary to ASI.