-
-
Save krzysztofzablocki/7913272 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#import <Foundation/Foundation.h> | |
@interface A : NSObject | |
- (void)doThingWithObject:(id)o completion:(void(^)(void))completionHandler; | |
@end | |
@implementation A | |
- (void)doThingWithObject:(id)o completion:(void(^)(void))completionHandler | |
{ | |
NSLog(@"object: %@", o); | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | |
if(completionHandler) completionHandler(); | |
}); | |
} | |
@end | |
int main(int argc, char *argv[]) { | |
@autoreleasepool { | |
A *a = [A new]; | |
NSArray *someThings = @[@0, @1, @2]; | |
__block NSMutableArray *commands = [NSMutableArray new]; | |
void(^step)(void) = ^() { | |
if (commands.count == 0) return; | |
void(^command)(void) = [commands firstObject]; | |
[commands removeObjectAtIndex:0]; | |
command(); | |
}; | |
NSEnumerator *e = [someThings objectEnumerator]; | |
id cur = [e nextObject]; | |
while (cur) { | |
[commands addObject:[^{ | |
[a doThingWithObject:cur completion:step]; | |
} copy]]; | |
cur = [e nextObject]; | |
} | |
step(); | |
sleep(1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment