mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-30 21:52:30 +08:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user