Permalink
Browse files

added private mutator for called_, use it.

  • Loading branch information...
1 parent 1a16115 commit 66bfbc2c7428ac5dcc7d5d6621cb5f87b5aca3ea @JimRoepcke committed May 17, 2012
Showing with 9 additions and 7 deletions.
  1. +9 −7 HLDeferred/Classes/HLDeferred.m
@@ -104,6 +104,7 @@ - (id) process: (id)input
@interface HLDeferred ()
+@property (nonatomic, readwrite, assign, getter=isCalled) BOOL called;
@property (nonatomic, strong) id result;
@property (nonatomic, strong) HLDeferred *chainedTo;
@@ -197,8 +198,8 @@ - (HLDeferred *) then: (ThenBlock)cb fail: (FailBlock)eb
} else {
HLLink *link = [[HLLink alloc] initWithThenBlock: cb failBlock: eb];
[chain_ addObject: link];
- link = nil;
- if (called_) {
+ link = nil;
+ if ([self isCalled]) {
[self _runCallbacks];
}
}
@@ -217,7 +218,7 @@ - (HLDeferred *) thenFinally: (ThenBlock)aThenFinalizer failFinally: (FailBlock)
@throw [self _alreadyHasAFinalizerException];
} else {
finalizer_ = [[HLLink alloc] initWithThenBlock: aThenFinalizer failBlock: aFailFinalizer];
- if (called_) {
+ if ([self isCalled]) {
[self _runCallbacks];
}
}
@@ -269,13 +270,13 @@ - (HLDeferred *) notify: (HLDeferred *)otherDeferred
- (void) cancel
{
- if (! called_) {
+ if (! [self isCalled]) {
if (canceller_) {
[canceller_ deferredWillCancel: self];
} else {
suppressAlreadyCalled_ = YES;
}
- if ( (! called_) && (canceller_ == nil) ) {
+ if ( (! [self isCalled]) && (canceller_ == nil) ) {
// if there is a canceller, the canceller
// must call [d takeError: kHLDeferredCancelled]
[self takeError: kHLDeferredCancelled];
@@ -329,14 +330,14 @@ - (void) _startRunCallbacks: (id)aResult
if (finalized_) {
@throw [self _alreadyFinalizedException];
}
- if (called_) {
+ if ([self isCalled]) {
if (suppressAlreadyCalled_) {
suppressAlreadyCalled_ = NO;
return;
}
@throw [self _alreadyCalledException];
}
- called_ = YES;
+ [self setCalled: YES];
[self setResult: aResult];
[self _runCallbacks];
}
@@ -364,6 +365,7 @@ - (void) _runCallbacks
}
BOOL finished = YES;
+ [current setCalled: YES];
[current setChainedTo: nil];
while ([current->chain_ count]) {
HLLink *item = [current->chain_ objectAtIndex: 0];

0 comments on commit 66bfbc2

Please sign in to comment.