Skip to content

Commit

Permalink
Merge pull request #78 from JosephEarl/feature/better-task-description
Browse files Browse the repository at this point in the history
Better -(NSString*)description for BFTask
  • Loading branch information
nlutsenko committed Jan 26, 2015
2 parents 8721616 + 49736ba commit 50b3310
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Bolts/Common/BFTask.m
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,29 @@ - (void)waitUntilFinished {
[self.condition unlock];
}

#pragma mark - NSObject

- (NSString *)description {
// Acquire the data from the locked properties
BOOL isCompleted;
BOOL isCancelled;
BOOL isFaulted;

@synchronized (self.lock) {
isCompleted = self.completed;
isCancelled = self.cancelled;
isFaulted = self.faulted;
}

// Description string includes status information and, if available, the
// result sisnce in some ways this is what a promise actually "is".
return [NSString stringWithFormat:@"<%@: %p; completed = %@; cancelled = %@; faulted = %@;%@>",
NSStringFromClass([self class]),
self,
isCompleted ? @"YES" : @"NO",
isCancelled ? @"YES" : @"NO",
isFaulted ? @"YES" : @"NO",
isCompleted ? [NSString stringWithFormat:@" result:%@", _result] : @""];
}

@end
9 changes: 9 additions & 0 deletions BoltsTests/TaskTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -534,4 +534,13 @@ - (void)testExecuteOnOperationQueue {
[task waitUntilFinished];
}

- (void)testDescription {
BFTask *task = [BFTask taskWithResult:nil];
NSString *expected = [NSString stringWithFormat:@"<BFTask: %p; completed = YES; cancelled = NO; faulted = NO; result:(null)>", task];

NSString *description = task.description;

XCTAssertTrue([expected isEqualToString:description]);
}

@end

0 comments on commit 50b3310

Please sign in to comment.