author | Jens Alfke <jens@mooseyard.com> |
Sun Apr 06 19:13:27 2008 -0700 (2008-04-06) | |
changeset 3 | 8fad19466c59 |
child 11 | e5976864dfe9 |
permissions | -rw-r--r-- |
jens@0 | 1 |
// |
jens@0 | 2 |
// ConcurrentOperation.m |
jens@0 | 3 |
// MYUtilities |
jens@0 | 4 |
// |
jens@0 | 5 |
// Created by Jens Alfke on 2/5/08. |
jens@0 | 6 |
// Copyright 2008 Jens Alfke. All rights reserved. |
jens@0 | 7 |
// |
jens@0 | 8 |
|
jens@0 | 9 |
#import "ConcurrentOperation.h" |
jens@0 | 10 |
|
jens@0 | 11 |
// 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 |
jens@0 | 12 |
|
jens@0 | 13 |
|
jens@0 | 14 |
@implementation ConcurrentOperation |
jens@0 | 15 |
|
jens@0 | 16 |
|
jens@0 | 17 |
- (BOOL) isConcurrent {return YES;} |
jens@0 | 18 |
|
jens@0 | 19 |
- (void) main |
jens@0 | 20 |
{ |
jens@0 | 21 |
Assert(NO,@"Shouldn't call -main method of ConcurrentOperation"); |
jens@0 | 22 |
} |
jens@0 | 23 |
|
jens@0 | 24 |
- (BOOL) isExecuting |
jens@0 | 25 |
{ |
jens@0 | 26 |
return _isExecuting; |
jens@0 | 27 |
} |
jens@0 | 28 |
|
jens@0 | 29 |
- (BOOL) isFinished |
jens@0 | 30 |
{ |
jens@0 | 31 |
return _isFinished; |
jens@0 | 32 |
} |
jens@0 | 33 |
|
jens@0 | 34 |
- (void) start |
jens@0 | 35 |
{ |
jens@0 | 36 |
// don't call super! |
jens@0 | 37 |
Log(@"Starting %@",self); |
jens@0 | 38 |
[self willChangeValueForKey: @"isExecuting"]; |
jens@0 | 39 |
_isExecuting = YES; |
jens@0 | 40 |
[self didChangeValueForKey: @"isExecuting"]; |
jens@0 | 41 |
} |
jens@0 | 42 |
|
jens@0 | 43 |
- (void) finish |
jens@0 | 44 |
{ |
jens@0 | 45 |
Log(@"Finished %@",self); |
jens@0 | 46 |
[self willChangeValueForKey: @"isExecuting"]; |
jens@0 | 47 |
[self willChangeValueForKey: @"isFinished"]; |
jens@0 | 48 |
_isExecuting = NO; |
jens@0 | 49 |
_isFinished = YES; |
jens@0 | 50 |
[self didChangeValueForKey: @"isFinished"]; |
jens@0 | 51 |
[self didChangeValueForKey: @"isExecuting"]; |
jens@0 | 52 |
} |
jens@0 | 53 |
|
jens@0 | 54 |
|
jens@0 | 55 |
- (void) cancel |
jens@0 | 56 |
{ |
jens@0 | 57 |
Log(@"Canceling %@",self); |
jens@0 | 58 |
[super cancel]; |
jens@0 | 59 |
if( _isExecuting ) { |
jens@0 | 60 |
[self willChangeValueForKey: @"isExecuting"]; |
jens@0 | 61 |
_isExecuting = NO; |
jens@0 | 62 |
[self didChangeValueForKey: @"isExecuting"]; |
jens@0 | 63 |
} |
jens@0 | 64 |
} |
jens@0 | 65 |
|
jens@0 | 66 |
|
jens@0 | 67 |
@end |