Simple NSOperation subclass that allows a block of asynchronous work to be executed in parallel in a NSOperationQueue
Objective-C Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
Sample Added sample project, updated README Mar 30, 2014
.gitignore
LICENSE
README.md
RNConcurrentBlockOperation.h
RNConcurrentBlockOperation.m
RNConcurrentBlockOperation.podspec

README.md

RNConcurrentBlockOperation

RNConcurrentBlockOperation is a simple NSOperation subclass, similar to NSBlockOperation. It allows a block of work that is potentially asynchrounous to be submited into a NSOperationQueue for parallel execution.

Sample usage:

    NSOperationQueue *queue = [NSOperationQueue new];
    queue.maxConcurrentOperationCount = 5;
    // Regular usage, only finishes the operation
    [queue addOperation:[RNConcurrentBlockOperation operationWithBlock:^(RNCompletionBlock completion) {
        NSLog(@"Concurrent op started");
        //Some async operation
        //... ... ...
        //Async operation completed
        completion(nil);
    }]];
    // Cancelled operation, cancels then finish the operation
    [queue addOperation:[RNConcurrentBlockOperation operationWithBlock:^(RNCompletionBlock completion) {
        NSLog(@"Cancellable op started");
        //Some async operation
        //... ... ...
        //Something happened (i.e user cancelled, network outage), and we want to bail
        //Async operation cancelled
        NSError *error = [NSError new]; //Some possible error
        completion(@{RNOperationStatusKey: RNOperationStatusCanceled, RNOperationErrorKey: error});
    }]];
    // Store the operation value in the userInfo dictionary and finishes it.
    [queue addOperation:[RNConcurrentBlockOperation operationWithBlock:^(RNCompletionBlock completion) {
        NSLog(@"Concurrent op started with result");
        NSString *result = @"A string generated by the async operation";
        completion(@{RNOperationResultKey: result});
    }]];