Browse files

handle case of passing exception on subsequent accesses to future

  • Loading branch information...
1 parent bf93fb9 commit c6bb09173d90b2fea8e40af8bd0ee8328290a349 @stevedekorte committed Sep 14, 2011
Showing with 25 additions and 16 deletions.
  1. +25 −16 ActorKit/FutureProxy.m
View
41 ActorKit/FutureProxy.m
@@ -118,23 +118,8 @@ - (BOOL)isWaitingOnCurrentThread
return NO;
}
-- futureResult
+- (void)futurePassExceptionIfNeeded
{
- if(done)
- {
- return futureValue;
- }
-
- [futureWaitingThreads addObject:[NSThread currentThread]];
-
- if([self isWaitingOnCurrentThread])
- {
- [NSException raise:@"Future" format:@"waiting for result on this coroutine would cause a deadlock"];
- return nil;
- }
-
- [futureLock pauseThread];
-
if(futureException)
{
// guessing we have to wrap the exception so the stack info of original will be available
@@ -147,10 +132,34 @@ - (BOOL)isWaitingOnCurrentThread
userInfo:info];
[e raise];
}
+}
+
+- (void)futureRaiseExceptionIfDeadlock
+{
+ if([self isWaitingOnCurrentThread])
+ {
+ [NSException raise:@"Future" format:@"waiting for result on this coroutine would cause a deadlock"];
+ }
+
+}
+
+- futureResult
+{
+ if(done)
+ {
+ [self futurePassExceptionIfNeeded];
+ return futureValue;
+ }
+
+ [futureWaitingThreads addObject:[NSThread currentThread]];
+ [self futureRaiseExceptionIfDeadlock];
+ [futureLock pauseThread];
+ [self futurePassExceptionIfNeeded];
return futureValue;
}
+
- (void)forwardInvocation:(NSInvocation *)anInvocation
{
[anInvocation invokeWithTarget:[self futureResult]];

0 comments on commit c6bb091

Please sign in to comment.