-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.m
More file actions
62 lines (45 loc) · 2.15 KB
/
main.m
File metadata and controls
62 lines (45 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Copyright 2011 Florian Agsteiner
*/
#import "FATask.h"
int main(int argc, char* argv[]) {
FATask* backgroundTask = [FATask startBackgroundTaskWithBlock:^id(FATask* task) {
NSLog(@"Task1: Background return 42");
return (id)[NSNumber numberWithInt:42];
}];
FATask* nextTask = [FABlockTask taskWithBlock:^id(FATask* task) {
NSLog(@"Task1: Background continuation return %@ / 2",[task result]);
id result = [NSNumber numberWithInt:[[task get] intValue]/2];
return result;
}];
[nextTask continueWithBlock:^(FATask *task) {
NSLog(@"Task1: Background continuation with result %@", [task result]);
}];
[backgroundTask continueWithTask:nextTask];
NSLog(@"Task1: Block and wait for result of task %@",[backgroundTask get]);
id result = [[[FATask startBackgroundTaskWithBlock:^id(FATask* task) {
return [NSSet setWithObjects:@"5",@"2",@"1",@"4",@"3", nil];
}] continueWithTask:[[FABlockTask taskWithBlock:^id(FATask* task) {
return [[task result] sortedArrayUsingComparator:^(id obj1, id obj2) {
return (NSComparisonResult)[obj1 compare:obj2 options:NSCaseInsensitiveSearch];
}];
}] continueWithBlock:^(FATask *task) {
NSLog(@"Task2: Sorted result %@", [task result]);
}]] get];
NSLog(@"Task2: Result unsorted because continuations only propergate result 1 level %@",result);
[[FATask startBackgroundTaskWithBlock:^id(FATask* task) {
return (id)[NSNumber numberWithInt:42];
}] continueWithMainThreadBlock:^(FATask* task) {
NSLog(@"Task3: Mainthread response %@", [task result]);
}];
[[FATask startMainThreadTaskWithBlock:^id(FATask* task) {
NSLog(@"Task4: main");
return (id)[NSNumber numberWithInt:42];
}] continueWithBackgroundTask:[[FABlockTask taskWithBlock:^id(FATask *task) {
NSLog(@"Task4: background");
return [NSNumber numberWithInt:[[task get] intValue]/2];
}] continueWithMainThreadBlock:^(FATask *task) {
NSLog(@"Task4: main result %@", [task result]);
}]];
return 0;
}