Created
November 21, 2012 05:11
-
-
Save kenji4569/4123150 to your computer and use it in GitHub Desktop.
simple block-based task queue with cascade
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
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