Created
August 15, 2016 16:14
-
-
Save gradyzhuo/ba6533231a9cad6a879b50f1798f2512 to your computer and use it in GitHub Desktop.
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
NSOperationQueue *queue = [[NSOperationQueue alloc] init]; | |
queue.maxConcurrentOperationCount = 1; | |
NSInteger inputValue = 5; | |
NSMutableArray<NSOperation *> *operations = [NSMutableArray<NSOperation *> array]; | |
for (NSInteger i=0; i<inputValue; i++){ | |
NSOperation *operation = [NSBlockOperation blockOperationWithBlock:^{ | |
NSLog(@".Running operation %d", i); | |
[NSThread sleepForTimeInterval:1]; | |
}]; | |
[operations addObject: operation]; | |
} | |
[operations[1] addDependency:operations[2]]; | |
[queue addOperations: operations waitUntilFinished:NO]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment