Permalink
Browse files

Futures can pass control to other futures.

This is ideally used as sort of a tail call.
  • Loading branch information...
1 parent 161bb79 commit 6a17ea569efd9f8f46567cfb46504408ada48a4e @robrix committed Mar 8, 2012
Showing with 10 additions and 0 deletions.
  1. +1 −0 RXFutures/RXFuture.h
  2. +9 −0 RXFutures/RXFuture.m
View
@@ -34,5 +34,6 @@
@property (nonatomic, readonly, assign, getter=isCompleted) BOOL completed;
-(void)cascadeCancellationToFuture:(RXFuture *)future; // cancels the argument when the receiver is cancelled
+-(void)passControlToFuture:(RXFuture *)future; // cancels the argument when the receiver is cancelled; cancels the receiver when the argument is cancelled; completes the receiver when the argument is completed
@end
View
@@ -122,4 +122,13 @@ -(void)cascadeCancellationToFuture:(RXFuture *)future {
[self onCancel:^{ [future cancel]; }];
}
+-(void)passControlToFuture:(RXFuture *)future {
+ if (future)
+ {
+ [self onCancel:^{ [future cancel]; }];
+ [future onCancel:^{ [self cancel]; }];
+ [future onComplete:^{ [self complete]; }];
+ }
+}
+
@end

0 comments on commit 6a17ea5

Please sign in to comment.