Skip to content
Newer
Older
100644 143 lines (78 sloc) 3.48 KB
60a321c @stevedekorte reorg and added README.txt
authored Aug 31, 2011
1
66acdc0 @stevedekorte Added BatchProxy
authored Sep 14, 2011
2 About
1f0cdcd @stevedekorte readme cleanup
authored Sep 13, 2011
3
30b24ea @stevedekorte REAMME update
authored Jun 12, 2012
4 ActorKit is a lightweight (under 300 semicolons) framework for multithreaded actors with transparent futures in Objective-C.
60a321c @stevedekorte reorg and added README.txt
authored Sep 1, 2011
5
66acdc0 @stevedekorte Added BatchProxy
authored Sep 15, 2011
6
b11f3d7 @stevedekorte docs cleanup
authored Sep 14, 2011
7 ActorProxy
66acdc0 @stevedekorte Added BatchProxy
authored Sep 15, 2011
8
c46d1d4 @stevedekorte asActor now always returns the same actor for a given instance
authored Sep 13, 2011
9 Sending an "asActor" message to any object returns an actor proxy for the object.
10
11 Sending messages to the actor will queue them to be processed in first-in-first-out order
12 by the actor's thread and immediately returns a "future" object.
85f934d @stevedekorte more readme updates
authored Sep 13, 2011
13
23146dd @adamv Typo
adamv authored Sep 29, 2011
14 If its message queue exceeds a given limit (set with setActorQueueLimit:),
e5a73dd @stevedekorte readme update
authored Sep 27, 2011
15 the calling threads that exceeded the limit will be paused until the more
16 of the queue is processed.
b11f3d7 @stevedekorte docs cleanup
authored Sep 15, 2011
17
18
1481e89 @stevedekorte more readme cleanup
authored Sep 13, 2011
19
b11f3d7 @stevedekorte docs cleanup
authored Sep 15, 2011
20 FutureProxy
dba6b64 @stevedekorte readme edits and cleanup
authored Sep 13, 2011
21
b11f3d7 @stevedekorte docs cleanup
authored Sep 15, 2011
22 A future is a transparent proxy for the result which, when accessed before the
e5a73dd @stevedekorte readme update
authored Sep 27, 2011
23 result is ready, pauses any threads attempting to access it until it is ready.
b11f3d7 @stevedekorte docs cleanup
authored Sep 15, 2011
24
25 Futures auto detect and raise an exception in deadlock situations.
26
66acdc0 @stevedekorte Added BatchProxy
authored Sep 15, 2011
27 Example
1481e89 @stevedekorte more readme cleanup
authored Sep 13, 2011
28
d569a2c @stevedekorte cleanup and renaming SyncProxy to ThreadSafeProxy
authored Sep 14, 2011
29 // the fetch return a future immediately
c46d1d4 @stevedekorte asActor now always returns the same actor for a given instance
authored Sep 14, 2011
30
b11f3d7 @stevedekorte docs cleanup
authored Sep 15, 2011
31 NSData *aFuture = [(NSURL *)[[@"http://yahoo.com" asURL] asActor] fetch];
c46d1d4 @stevedekorte asActor now always returns the same actor for a given instance
authored Sep 14, 2011
32
d569a2c @stevedekorte cleanup and renaming SyncProxy to ThreadSafeProxy
authored Sep 15, 2011
33 // ... do stuff ...
0da6c31 @stevedekorte updated readme
authored Sep 12, 2011
34
e5a73dd @stevedekorte readme update
authored Sep 27, 2011
35 // now when we try to access the values,
36 // the thread waits if the values aren't ready
c46d1d4 @stevedekorte asActor now always returns the same actor for a given instance
authored Sep 14, 2011
37
b11f3d7 @stevedekorte docs cleanup
authored Sep 15, 2011
38 NSLog(@"request returned %i bytes", (int)[aFuture length]);
66acdc0 @stevedekorte Added BatchProxy
authored Sep 15, 2011
39
40
41
d569a2c @stevedekorte cleanup and renaming SyncProxy to ThreadSafeProxy
authored Sep 15, 2011
42 ThreadSafeProxy
66acdc0 @stevedekorte Added BatchProxy
authored Sep 15, 2011
43
d569a2c @stevedekorte cleanup and renaming SyncProxy to ThreadSafeProxy
authored Sep 15, 2011
44 Calling asThreadSafe on any object returns a proxy that ensures only one thread
45 can access it at a time. Example:
66acdc0 @stevedekorte Added BatchProxy
authored Sep 15, 2011
46
d569a2c @stevedekorte cleanup and renaming SyncProxy to ThreadSafeProxy
authored Sep 15, 2011
47 NSMutableDictionary *dict = [[NSMutableDictionary dictionary] asThreadSafe];
66acdc0 @stevedekorte Added BatchProxy
authored Sep 15, 2011
48
49
50
51
52 BatchProxy
53
638969e @stevedekorte fixes and cleanup
authored Sep 14, 2011
54 Calling asBatch on an NSArray returns a BatchProxy which can be used to do
66acdc0 @stevedekorte Added BatchProxy
authored Sep 15, 2011
55 a parallel "map" using GCD (BSD workerqueues). Example:
56
57 NSArray *results = [[urls asBatch] fetch];
d569a2c @stevedekorte cleanup and renaming SyncProxy to ThreadSafeProxy
authored Sep 15, 2011
58
59 Sends concurrent fetch messages to each element of the urls array and returns
60 an array containing the results.
66acdc0 @stevedekorte Added BatchProxy
authored Sep 15, 2011
61
8b3d5ca @stevedekorte updated readme with pauseThread and resumeThread info
authored Sep 14, 2012
62
63
64
65 Dealing with Async Callbacks
66
67 To deal with async callbacks within an actor's thread, pauseThread and resumeThread can be used. Example:
68
69
70 __block id response = nil;
71 __block NSError *error = nil;
72 __block ActorProxy *actor = [ActorProxy currentActorProxy];
73
74 _request = [s3Client getBucket:_bucketName
75 success:^(id responseObject)
76 {
77 response = responseObject;
78 [actor resumeThread];
79 }
80 failure:^(NSError *e)
81 {
82 error = e;
83 [actor resumeThread];
84 }
85 ];
86
87 id returnValue = [[ActorProxy currentActorProxy] pauseThread];
88
89 if(error)
90 {
91 [NSException raise:@"SyncKitError" format:[error description]];
92 }
93
94 Also, if the thread is resumed using resumeThreadWithValue:, the pauseThread method will return the given value.
9f98bf6 @stevedekorte changed some property names to avoid conflicts with proxy targets
authored Sep 13, 2011
95
66acdc0 @stevedekorte Added BatchProxy
authored Sep 15, 2011
96 Notes
26343ab @stevedekorte added credits
authored Sep 13, 2011
97
bf93fb9 @stevedekorte readme notes added
authored Sep 13, 2011
98 Exceptions that occur while an actor processes a message will be
61559a4 @stevedekorte doc update
authored Oct 2, 2011
99 passed to the future and raised in all the threads that attempt
100 to access the future.
bf93fb9 @stevedekorte readme notes added
authored Sep 14, 2011
101
9f98bf6 @stevedekorte changed some property names to avoid conflicts with proxy targets
authored Sep 13, 2011
102 It's ok for multiple threads to look at the same future.
103
104 ActorKit does no busy waits.
105
b11f3d7 @stevedekorte docs cleanup
authored Sep 15, 2011
106 Objects store their proxies as an associated objects so the same
61559a4 @stevedekorte doc update
authored Oct 3, 2011
107 proxy is returned for a given instance.
c46d1d4 @stevedekorte asActor now always returns the same actor for a given instance
authored Sep 14, 2011
108
459ab97 @stevedekorte adding SyncProxy
authored Sep 13, 2011
109
66acdc0 @stevedekorte Added BatchProxy
authored Sep 15, 2011
110
8b3d5ca @stevedekorte updated readme with pauseThread and resumeThread info
authored Sep 14, 2012
111
66acdc0 @stevedekorte Added BatchProxy
authored Sep 15, 2011
112 To Do
113
325deca @stevedekorte BatchProxy fixes - passing basic test
authored Sep 14, 2011
114 - handle BatchProxy exceptions
115
d569a2c @stevedekorte cleanup and renaming SyncProxy to ThreadSafeProxy
authored Sep 15, 2011
116 - make sure all locks deal with exceptions
117
66acdc0 @stevedekorte Added BatchProxy
authored Sep 15, 2011
118 - future notifications of some kind
459ab97 @stevedekorte adding SyncProxy
authored Sep 14, 2011
119
d569a2c @stevedekorte cleanup and renaming SyncProxy to ThreadSafeProxy
authored Sep 15, 2011
120 - more tests
459ab97 @stevedekorte adding SyncProxy
authored Sep 14, 2011
121
61559a4 @stevedekorte doc update
authored Oct 3, 2011
122 - auto deadlock detection for actor queue limit and batches
459ab97 @stevedekorte adding SyncProxy
authored Sep 14, 2011
123
66acdc0 @stevedekorte Added BatchProxy
authored Sep 15, 2011
124 - add a total queue and/or total actor limits
459ab97 @stevedekorte adding SyncProxy
authored Sep 14, 2011
125
66acdc0 @stevedekorte Added BatchProxy
authored Sep 15, 2011
126 - better respondsToSelector implementation
638969e @stevedekorte fixes and cleanup
authored Sep 15, 2011
127
61559a4 @stevedekorte doc update
authored Oct 3, 2011
128 - (maybe) chainable persistent batch groups with in, out, and error queues
66acdc0 @stevedekorte Added BatchProxy
authored Sep 15, 2011
129
61559a4 @stevedekorte doc update
authored Oct 3, 2011
130 - (maybe) integrate with distibuted objects to allow bundles and data to
131 be distributed...
66acdc0 @stevedekorte Added BatchProxy
authored Sep 15, 2011
132
61559a4 @stevedekorte doc update
authored Oct 3, 2011
133 - (maybe) explore synchronization via ownership
dba6b64 @stevedekorte readme edits and cleanup
authored Sep 13, 2011
134
66acdc0 @stevedekorte Added BatchProxy
authored Sep 15, 2011
135 Credits
26343ab @stevedekorte added credits
authored Sep 13, 2011
136
66acdc0 @stevedekorte Added BatchProxy
authored Sep 15, 2011
137 Thanks to Mark Papadakis for tips on mutex conditions.
138 IIRC I saw the BatchProxy pattern first used in Io by quag.
bfe2da2 @stevedekorte doc update
authored Oct 2, 2011
139
140 If you use this project, please drop me a line and let me
141 know if you found it useful. Thanks.
bf93fb9 @stevedekorte readme notes added
authored Sep 14, 2011
142
143
Something went wrong with that request. Please try again.