Permalink
Browse files

Futures guard against nil arguments.

  • Loading branch information...
1 parent f83ef69 commit b102c9d991fff3a96bdccf3b9e2b152ebb890086 @robrix committed Feb 13, 2012
Showing with 24 additions and 13 deletions.
  1. +2 −0 RXFutures/RXFuture.h
  2. +22 −13 RXFutures/RXFuture.m
View
@@ -13,6 +13,8 @@
dispatch_queue_t queue;
}
++(RXFuture *)future;
+
-(void)onComplete:(void(^)())block;
-(void)complete;
-(void)complete:(void(^)())block; // shorthand for -onComplete: followed by -complete
View
@@ -15,6 +15,12 @@ @implementation RXFuture
@synthesize cancelled, completed;
+
++(RXFuture *)future {
+ return [[self new] autorelease];
+}
+
+
-(id)init {
if((self = [super init])) {
completionHandlers = [NSMutableSet new];
@@ -38,12 +44,13 @@ -(void)dispatchCallback:(void(^)())block {
-(void)onCancel:(void(^)())block {
- [self performBlock:^{
- if(cancelled)
- [self dispatchCallback:block];
- else
- [cancellationHandlers addObject:block];
- }];
+ if(block)
+ [self performBlock:^{
+ if(cancelled)
+ [self dispatchCallback:block];
+ else
+ [cancellationHandlers addObject:block];
+ }];
}
-(void)cancel {
@@ -64,12 +71,13 @@ -(void)cancel:(void(^)())block {
-(void)onComplete:(void(^)())block {
- [self performBlock:^{
- if(completed)
- [self dispatchCallback:block];
- else
- [completionHandlers addObject:block];
- }];
+ if(block)
+ [self performBlock:^{
+ if(completed)
+ [self dispatchCallback:block];
+ else
+ [completionHandlers addObject:block];
+ }];
}
-(void)complete {
@@ -102,7 +110,8 @@ -(void)unlessCancelled:(void(^)())block {
-(void)cascadeCancellationToFuture:(RXFuture *)future {
- [self onCancel:^{ [future cancel]; }];
+ if(future)
+ [self onCancel:^{ [future cancel]; }];
}
@end

0 comments on commit b102c9d

Please sign in to comment.