1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/ConcurrentOperation.m Fri May 02 12:49:43 2008 -0700
1.3 @@ -0,0 +1,67 @@
1.4 +//
1.5 +// ConcurrentOperation.m
1.6 +// MYUtilities
1.7 +//
1.8 +// Created by Jens Alfke on 2/5/08.
1.9 +// Copyright 2008 Jens Alfke. All rights reserved.
1.10 +//
1.11 +
1.12 +#import "ConcurrentOperation.h"
1.13 +
1.14 +// See file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/NSOperation_class/Reference/Reference.html#//apple_ref/doc/uid/TP40004591-RH2-DontLinkElementID_4
1.15 +
1.16 +
1.17 +@implementation ConcurrentOperation
1.18 +
1.19 +
1.20 +- (BOOL) isConcurrent {return YES;}
1.21 +
1.22 +- (void) main
1.23 +{
1.24 + Assert(NO,@"Shouldn't call -main method of ConcurrentOperation");
1.25 +}
1.26 +
1.27 +- (BOOL) isExecuting
1.28 +{
1.29 + return _isExecuting;
1.30 +}
1.31 +
1.32 +- (BOOL) isFinished
1.33 +{
1.34 + return _isFinished;
1.35 +}
1.36 +
1.37 +- (void) start
1.38 +{
1.39 + // don't call super!
1.40 + Log(@"Starting %@",self);
1.41 + [self willChangeValueForKey: @"isExecuting"];
1.42 + _isExecuting = YES;
1.43 + [self didChangeValueForKey: @"isExecuting"];
1.44 +}
1.45 +
1.46 +- (void) finish
1.47 +{
1.48 + Log(@"Finished %@",self);
1.49 + [self willChangeValueForKey: @"isExecuting"];
1.50 + [self willChangeValueForKey: @"isFinished"];
1.51 + _isExecuting = NO;
1.52 + _isFinished = YES;
1.53 + [self didChangeValueForKey: @"isFinished"];
1.54 + [self didChangeValueForKey: @"isExecuting"];
1.55 +}
1.56 +
1.57 +
1.58 +- (void) cancel
1.59 +{
1.60 + Log(@"Canceling %@",self);
1.61 + [super cancel];
1.62 + if( _isExecuting ) {
1.63 + [self willChangeValueForKey: @"isExecuting"];
1.64 + _isExecuting = NO;
1.65 + [self didChangeValueForKey: @"isExecuting"];
1.66 + }
1.67 +}
1.68 +
1.69 +
1.70 +@end