Permalink
Browse files

Adds a convenience method to safely perform a block unless the future…

… has been cancelled.
  • Loading branch information...
1 parent 605c437 commit e3358e75f7667c481c167018d740b1f98f3d33b0 @robrix committed Feb 11, 2012
Showing with 14 additions and 6 deletions.
  1. +2 −0 RXFutures/RXFuture.h
  2. +12 −6 RXFutures/RXFuture.m
@@ -23,6 +23,8 @@
-(void)performBlock:(void(^)())block;
+-(void)unlessCancelled:(void(^)())block;
+
// 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=isCompleted) BOOL completed;
View
@@ -37,12 +37,6 @@ -(void)dispatchCallback:(void(^)())block {
}
--(void)performBlock:(void(^)())block
-{
- dispatch_async(queue, block);
-}
-
-
-(void)onCancel:(void(^)())block {
[self performBlock:^{
if(cancelled)
@@ -94,4 +88,16 @@ -(void)complete:(void(^)())block {
[self complete];
}
+
+-(void)performBlock:(void(^)())block {
+ dispatch_async(queue, block);
+}
+
+
+-(void)unlessCancelled:(void(^)())block {
+ [self performBlock:^{
+ if(!cancelled) block();
+ }];
+}
+
@end

0 comments on commit e3358e7

Please sign in to comment.