Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
Adds a convenience method to safely perform a block unless the future…
Browse files Browse the repository at this point in the history
… has been cancelled.
  • Loading branch information
robrix committed Feb 11, 2012
1 parent 605c437 commit e3358e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions RXFutures/RXFuture.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@


-(void)performBlock:(void(^)())block; -(void)performBlock:(void(^)())block;


-(void)unlessCancelled:(void(^)())block;

// these properties are only meaningful and safe within blocks passed to -performBlock: // these properties are only meaningful and safe within blocks passed to -performBlock:
@property (nonatomic, readonly, assign, getter=isCancelled) BOOL cancelled; @property (nonatomic, readonly, assign, getter=isCancelled) BOOL cancelled;
@property (nonatomic, readonly, assign, getter=isCompleted) BOOL completed; @property (nonatomic, readonly, assign, getter=isCompleted) BOOL completed;
Expand Down
18 changes: 12 additions & 6 deletions RXFutures/RXFuture.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ -(void)dispatchCallback:(void(^)())block {
} }




-(void)performBlock:(void(^)())block
{
dispatch_async(queue, block);
}


-(void)onCancel:(void(^)())block { -(void)onCancel:(void(^)())block {
[self performBlock:^{ [self performBlock:^{
if(cancelled) if(cancelled)
Expand Down Expand Up @@ -94,4 +88,16 @@ -(void)complete:(void(^)())block {
[self complete]; [self complete];
} }



-(void)performBlock:(void(^)())block {
dispatch_async(queue, block);
}


-(void)unlessCancelled:(void(^)())block {
[self performBlock:^{
if(!cancelled) block();
}];
}

@end @end

0 comments on commit e3358e7

Please sign in to comment.