Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt to detect circular dependencies in operations
- Loading branch information
Andy Mroczkowski
committed
Mar 28, 2013
1 parent
aa7b910
commit 0f6dbe0
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,19 @@ | |||
// | |||
// NSOperation+Zinc.h | |||
// Zinc-ObjC | |||
// | |||
// Created by Andy Mroczkowski on 3/28/13. | |||
// Copyright (c) 2013 MindSnacks. All rights reserved. | |||
// | |||
|
|||
#import <Foundation/Foundation.h> | |||
|
|||
@interface NSOperation (Zinc) | |||
|
|||
|
|||
/** | |||
@discussion returns ALL dependencies of the operation, recursively. | |||
*/ | |||
- (NSArray*) zinc_allDependencies; | |||
|
|||
@end |
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,38 @@ | |||
// | |||
// NSOperation+Zinc.m | |||
// Zinc-ObjC | |||
// | |||
// Created by Andy Mroczkowski on 3/28/13. | |||
// Copyright (c) 2013 MindSnacks. All rights reserved. | |||
// | |||
|
|||
#import "NSOperation+Zinc.h" | |||
|
|||
@implementation NSOperation (Zinc) | |||
|
|||
- (NSArray*) zinc_allDependencies | |||
{ | |||
NSMutableArray *todo = [NSMutableArray arrayWithObject:self]; | |||
NSMutableSet *done = [NSMutableSet set]; | |||
NSMutableArray *allDeps = [NSMutableArray array]; | |||
|
|||
while ([todo count] > 0) { | |||
|
|||
NSOperation *op = [todo lastObject]; | |||
[todo removeLastObject]; | |||
[done addObject:op]; | |||
|
|||
NSArray* deps = [op dependencies]; | |||
for (id obj in deps) { | |||
[allDeps addObject:obj]; | |||
if (![done containsObject:obj]) { | |||
[todo addObject:obj]; | |||
} | |||
} | |||
} | |||
|
|||
return allDeps; | |||
} | |||
|
|||
@end | |||
|
This file contains 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