Created
May 6, 2017 17:24
-
-
Save mbbischoff/48a07749f59389ac74fb959b0708f89c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// LCKConcurrentOperation.m | |
// LCKOperations | |
// | |
// Created by Twig on 12/19/13. | |
// Copyright (c) 2013 Lickability. All rights reserved. | |
// | |
#import "LCKConcurrentOperation.h" | |
@interface LCKConcurrentOperation () | |
@property (nonatomic, getter = isExecuting) BOOL executing; | |
@property (nonatomic, getter = isFinished) BOOL finished; | |
@end | |
@implementation LCKConcurrentOperation | |
@synthesize executing = _executing; | |
@synthesize finished = _finished; | |
- (void)start { | |
if ([self isCancelled]) { | |
self.finished = YES; | |
return; | |
} | |
[super start]; | |
self.executing = YES; | |
} | |
- (void)main { | |
@try { | |
[self performConcurrentWork]; | |
} | |
@catch (NSException *exception) { | |
NSAssert(!exception, nil); | |
} | |
} | |
- (void)setFinished:(BOOL)finished { | |
if (_finished == finished) { | |
return; | |
} | |
NSString *isFinishedSelectorString = NSStringFromSelector(@selector(isFinished)); | |
[self willChangeValueForKey:isFinishedSelectorString]; | |
_finished = finished; | |
[self didChangeValueForKey:isFinishedSelectorString]; | |
if (finished) { | |
self.executing = NO; | |
} | |
} | |
- (void)setExecuting:(BOOL)executing { | |
if (_executing == executing) { | |
return; | |
} | |
NSString *isExecutingSelectorString = NSStringFromSelector(@selector(isExecuting)); | |
[self willChangeValueForKey:isExecutingSelectorString]; | |
_executing = executing; | |
[self didChangeValueForKey:isExecutingSelectorString]; | |
} | |
- (BOOL)isConcurrent { | |
return YES; | |
} | |
- (void)performConcurrentWork { | |
NSAssert(NO, @"Subclasses must override %@", NSStringFromSelector(_cmd)); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment