//
//  ConcurrentOperation.m
//  MYUtilities
//
//  Created by Jens Alfke on 2/5/08.
//  Copyright 2008 Jens Alfke. All rights reserved.
//

#import "ConcurrentOperation.h"

// 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


@implementation ConcurrentOperation


- (BOOL) isConcurrent {return YES;}

- (void) main
{
    Assert(NO,@"Shouldn't call -main method of ConcurrentOperation");
}

- (BOOL) isExecuting
{
    return _isExecuting;
}

- (BOOL) isFinished
{
    return _isFinished;
}

- (void) start
{
    // don't call super!
    Log(@"Starting %@",self);
    [self willChangeValueForKey: @"isExecuting"];
    _isExecuting = YES;
    [self didChangeValueForKey: @"isExecuting"];
}

- (void) finish
{
    Log(@"Finished %@",self);
    [self willChangeValueForKey: @"isExecuting"];
    [self willChangeValueForKey: @"isFinished"];
    _isExecuting = NO;
    _isFinished = YES;
    [self didChangeValueForKey: @"isFinished"];
    [self didChangeValueForKey: @"isExecuting"];
}


- (void) cancel
{
    Log(@"Canceling %@",self);
    [super cancel];
    if( _isExecuting ) {
        [self willChangeValueForKey: @"isExecuting"];
        _isExecuting = NO;
        [self didChangeValueForKey: @"isExecuting"];
    }
}


@end
