Implement support for cancellation and prioritization of response mapping operations using an operation queue global to all object request operations.

* Passes through cancellation from object request operation to HTTP request operation and response mapping operation. closes #993
* Performs all object mapping within an NSOperationQueue to enable constraining of mapping activities.
* Add default mapping queue with concurrency limit of 1 operation.
* Migrate deserialization of the response body into a serial dispatch queue to ensure that only one parse occurs at a time.
This commit is contained in:
Blake Watters
2012-10-20 00:13:48 -04:00
parent 0738f59231
commit 08110ca300
8 changed files with 181 additions and 52 deletions

View File

@@ -510,4 +510,25 @@
}
}
- (void)testCancellationOfMapperOperation
{
RKObjectMapping *childMapping = [RKObjectMapping mappingForClass:[RKTestUser class]];
[childMapping addAttributeMappingsFromArray:@[@"name"]];
RKEntityMapping *parentMapping = [RKObjectMapping mappingForClass:[RKTestUser class]];
[parentMapping addAttributeMappingsFromArray:@[@"name"]];
[parentMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"children" toKeyPath:@"friends" withMapping:childMapping]];
NSDictionary *mappingsDictionary = @{ @"parents": parentMapping };
NSOperationQueue *operationQueue = [NSOperationQueue new];
NSDictionary *JSON = [RKTestFixture parsedObjectWithContentsOfFixture:@"benchmark_parents_and_children.json"];
RKMapperOperation *mapper = [[RKMapperOperation alloc] initWithObject:JSON mappingsDictionary:mappingsDictionary];
[operationQueue addOperation:mapper];
[mapper cancel];
[operationQueue waitUntilAllOperationsAreFinished];
expect([mapper isCancelled]).to.equal(YES);
expect(mapper.error).to.beNil();
expect(mapper.mappingResult).to.beNil();
}
@end