Skip to content

Commit

Permalink
Merge pull request #106 from BoltsFramework/nlutsenko.cancellation
Browse files Browse the repository at this point in the history
Fixed never completed task if continuation returns a task and cancellation was requested.
  • Loading branch information
nlutsenko committed Jun 25, 2015
2 parents 387ff4a + 9a7ae34 commit 494a66f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Bolts/Common/BFTask.m
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ - (instancetype)continueWithExecutor:(BFExecutor *)executor
if ([result isKindOfClass:[BFTask class]]) {

id (^setupWithTask) (BFTask *) = ^id(BFTask *task) {
if (task.cancelled) {
if (cancellationToken.cancellationRequested || task.cancelled) {
[tcs cancel];
} else if (task.exception) {
tcs.exception = task.exception;
Expand All @@ -357,7 +357,7 @@ - (instancetype)continueWithExecutor:(BFExecutor *)executor
if (resultTask.completed) {
setupWithTask(resultTask);
} else {
[resultTask continueWithBlock:setupWithTask cancellationToken:cancellationToken];
[resultTask continueWithBlock:setupWithTask];
}

} else {
Expand Down
15 changes: 15 additions & 0 deletions BoltsTests/TaskTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -692,4 +692,19 @@ - (void)testDescription {
XCTAssertTrue([expected isEqualToString:description]);
}

- (void)testReturnTaskFromContinuationWithCancellation {
BFCancellationTokenSource *cts = [BFCancellationTokenSource cancellationTokenSource];

XCTestExpectation *expectation = [self expectationWithDescription:@"task"];
[[[BFTask taskWithDelay:1] continueWithBlock:^id(BFTask *task) {
[cts cancel];
return [BFTask taskWithDelay:10];
} cancellationToken:cts.token] continueWithBlock:^id(BFTask *task) {
XCTAssertTrue(task.cancelled);
[expectation fulfill];
return nil;
}];
[self waitForExpectationsWithTimeout:10.0 handler:nil];
}

@end

0 comments on commit 494a66f

Please sign in to comment.