ConcurrentOperation.m
author Jens Alfke <jens@mooseyard.com>
Tue Jun 17 14:57:48 2008 -0700 (2008-06-17)
changeset 14 1af6415650bf
parent 11 e5976864dfe9
child 26 252c13061ee5
permissions -rw-r--r--
Added AudioUtils.
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@14
    11
// See file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/NSOperation_class/Reference/Reference.html
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
jens@11
    68
jens@11
    69
jens@11
    70
/*
jens@11
    71
 Copyright (c) 2008, Jens Alfke <jens@mooseyard.com>. All rights reserved.
jens@11
    72
 
jens@11
    73
 Redistribution and use in source and binary forms, with or without modification, are permitted
jens@11
    74
 provided that the following conditions are met:
jens@11
    75
 
jens@11
    76
 * Redistributions of source code must retain the above copyright notice, this list of conditions
jens@11
    77
 and the following disclaimer.
jens@11
    78
 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
jens@11
    79
 and the following disclaimer in the documentation and/or other materials provided with the
jens@11
    80
 distribution.
jens@11
    81
 
jens@11
    82
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
jens@11
    83
 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
jens@11
    84
 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
jens@11
    85
 BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
jens@11
    86
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
jens@11
    87
  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
jens@11
    88
 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
jens@11
    89
 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
jens@11
    90
 */