Permalink
Browse files

KSRunOperationOnThreadOperation

  • Loading branch information...
mikeabdullah committed Jul 2, 2011
1 parent ccd9846 commit 74303ef00d1166795c28467db175cd4a44828f6f
Showing with 74 additions and 0 deletions.
  1. +22 −0 KSThreadProxy.h
  2. +52 −0 KSThreadProxy.m
View
@@ -46,3 +46,25 @@
@end
+
+#pragma mark -
+
+
+@interface KSRunOperationOnThreadOperation : NSOperation
+{
+ @private
+ NSOperation *_operation;
+ NSThread *_thread;
+}
+
+// Thread may be nil to signify main
+- (id)initWithOperation:(NSOperation *)operation thread:(NSThread *)thread;
+
+@property(nonatomic, retain, readonly) NSOperation *targetOperation;
+
+// A KSRunOperationOnThreadOperation is only ready once the operation it contains is
+- (BOOL)isReady;
+
+@end
+
+
View
@@ -144,3 +144,55 @@ - (id)ks_proxyOnThread:(NSThread *)thread waitUntilDone:(BOOL)waitUntilDone;
@end
+#pragma mark -
+
+
+@implementation KSRunOperationOnThreadOperation
+
+- (id)initWithOperation:(NSOperation *)operation thread:(NSThread *)thread;
+{
+ OBPRECONDITION(operation);
+
+ if (self = [self init])
+ {
+ _operation = [operation retain];
+ _thread = [_thread retain];
+ }
+
+ return self;
+}
+
+- (void)dealloc
+{
+ [_operation release];
+ [_thread release];
+
+ [super dealloc];
+}
+
+@synthesize targetOperation = _operation;
+
+- (void)main
+{
+ [(NSOperation *)[_operation ks_proxyOnThread:_thread waitUntilDone:NO] start];
+}
+
+- (BOOL)isReady
+{
+ return [super isReady] && [_operation isReady];
+}
++ (NSSet *)keyPathsForValuesAffectingIsReady;
+{
+ NSSet *result = [NSSet setWithObject:@"targetOperation.isReady"];
+
+ if ([NSOperation respondsToSelector:_cmd])
+ {
+ result = [result setByAddingObjectsFromSet:[NSOperation performSelector:_cmd]];
+ }
+
+ return result;
+}
+
+@end
+
+

0 comments on commit 74303ef

Please sign in to comment.