Skip to content

Commit

Permalink
Fix disposing of CancellationTokenSource with registrations.
Browse files Browse the repository at this point in the history
  • Loading branch information
nlutsenko committed Feb 2, 2016
1 parent beac943 commit 37d6aa8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Bolts/Common/BFCancellationToken.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,9 @@ - (void)dispose {
if (self.disposed) {
return;
}
[self.registrations makeObjectsPerformSelector:@selector(dispose)];
self.registrations = nil;
self.disposed = YES;
for (BFCancellationTokenRegistration *registration in self.registrations) {
[registration dispose];
}
[self.registrations removeAllObjects];
}
}

Expand Down
8 changes: 8 additions & 0 deletions BoltsTests/CancellationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,12 @@ - (void)testDispose {
XCTAssertThrowsSpecificNamed(cts.token.cancellationRequested, NSException, NSInternalInconsistencyException);
}

- (void)testDisposeRegistrationBeforeCancellationToken {
BFCancellationTokenSource *cts = [BFCancellationTokenSource cancellationTokenSource];
BFCancellationTokenRegistration *registration = [cts.token registerCancellationObserverWithBlock:^{ }];

[cts dispose];
XCTAssertNoThrow([registration dispose]);
}

@end

0 comments on commit 37d6aa8

Please sign in to comment.