Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance group cancel. #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions Source/PINOperationGroup.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ - (void)start
dispatch_block_t groupBlock = ^{
originalOperation();
dispatch_group_leave(self->_group);
[self removeOperationReferenceWithIndex:idx];
};

id <PINOperationReference> operationReference = [_operationQueue scheduleOperation:groupBlock withPriority:[_operationPriorities[idx] unsignedIntegerValue]];
Expand All @@ -94,10 +95,6 @@ - (void)start
[self runCompletionIfNeeded];
});
}

_operations = nil;
_operationPriorities = nil;
_operationReferences = nil;
}
[self unlock];
}
Expand All @@ -113,16 +110,30 @@ - (void)cancel
}
}

//TODO just nil out instead? Does it make sense to support adding operations after cancelation?
[_groupToOperationReferences removeAllObjects];
[_operations removeAllObjects];
[_operationPriorities removeAllObjects];
[_operationReferences removeAllObjects];
//Make sense to support adding operations after completion or cancelation
[self locked_removeAllOperations];

_completion = nil;
[self unlock];
}

- (void)removeOperationReferenceWithIndex:(NSUInteger)index
{
[self lock];
if (index < _operationReferences.count) {
[_groupToOperationReferences removeObjectForKey:_operationReferences[index]];
}
[self unlock];
}

- (void)locked_removeAllOperations
{
[_groupToOperationReferences removeAllObjects];
[_operations removeAllObjects];
[_operationPriorities removeAllObjects];
[_operationReferences removeAllObjects];
}

- (id <PINGroupOperationReference>)addOperation:(dispatch_block_t)operation
{
return [self addOperation:operation withPriority:PINOperationQueuePriorityDefault];
Expand Down Expand Up @@ -167,6 +178,7 @@ - (void)runCompletionIfNeeded
[self lock];
completion = _completion;
_completion = nil;
[self locked_removeAllOperations];
[self unlock];

if (completion) {
Expand Down