Skip to content

Instantly share code, notes, and snippets.

@gradyzhuo
Created August 15, 2016 16:14
Show Gist options
  • Save gradyzhuo/ba6533231a9cad6a879b50f1798f2512 to your computer and use it in GitHub Desktop.
Save gradyzhuo/ba6533231a9cad6a879b50f1798f2512 to your computer and use it in GitHub Desktop.
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