Skip to content

Instantly share code, notes, and snippets.

@kenji4569
Created November 21, 2012 05:11
Show Gist options
  • Save kenji4569/4123150 to your computer and use it in GitHub Desktop.
Save kenji4569/4123150 to your computer and use it in GitHub Desktop.
simple block-based task queue with cascade
NSMutableArray *tasks = [[NSMutableArray alloc] init];
void (^nextTask)() = ^() {
[tasks removeObjectAtIndex: 0];
if ([tasks count] > 0) {
void (^task)() = [tasks objectAtIndex: 0];
task();
}
};
[tasks addObject: ^() {
NSLog(@"task1");
nextTask();
}];
[tasks addObject: ^() {
NSLog(@"task2");
nextTask();
}];
void (^task)() = [tasks objectAtIndex: 0];
task();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment