Permalink
Browse files

Turns out +keyPathsForValuesAffectingIsReady is no good on operations

  • Loading branch information...
1 parent 74303ef commit 908eced90df7fa2c55ee632c34d665fec0e82284 @mikeabdullah mikeabdullah committed Jul 2, 2011
Showing with 30 additions and 0 deletions.
  1. +30 −0 KSThreadProxy.m
View
@@ -149,6 +149,8 @@ - (id)ks_proxyOnThread:(NSThread *)thread waitUntilDone:(BOOL)waitUntilDone;
@implementation KSRunOperationOnThreadOperation
+static void *sIsReadyObservationContext = &sIsReadyObservationContext;
+
- (id)initWithOperation:(NSOperation *)operation thread:(NSThread *)thread;
{
OBPRECONDITION(operation);
@@ -157,13 +159,20 @@ - (id)initWithOperation:(NSOperation *)operation thread:(NSThread *)thread;
{
_operation = [operation retain];
_thread = [_thread retain];
+
+ [_operation addObserver:self
+ forKeyPath:@"isReady"
+ options:NSKeyValueObservingOptionPrior
+ context:sIsReadyObservationContext];
}
return self;
}
- (void)dealloc
{
+ [_operation removeObserver:self forKeyPath:@"isReady"];
+
[_operation release];
[_thread release];
@@ -177,6 +186,8 @@ - (void)main
[(NSOperation *)[_operation ks_proxyOnThread:_thread waitUntilDone:NO] start];
}
+#pragma mark Readiness
+
- (BOOL)isReady
{
return [super isReady] && [_operation isReady];
@@ -193,6 +204,25 @@ + (NSSet *)keyPathsForValuesAffectingIsReady;
return result;
}
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context;
+{
+ if (context == sIsReadyObservationContext)
+ {
+ if ([[change objectForKey:NSKeyValueChangeNotificationIsPriorKey] boolValue])
+ {
+ [self willChangeValueForKey:@"isReady"];
+ }
+ else
+ {
+ [self didChangeValueForKey:@"isReady"];
+ }
+ }
+ else
+ {
+ [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
+ }
+}
+
@end

0 comments on commit 908eced

Please sign in to comment.