Skip to content

Instantly share code, notes, and snippets.

@mattbischoff
Created May 6, 2017 17:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattbischoff/48a07749f59389ac74fb959b0708f89c to your computer and use it in GitHub Desktop.
Save mattbischoff/48a07749f59389ac74fb959b0708f89c to your computer and use it in GitHub Desktop.
//
// 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