Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Objective-C multithreaded actors & futures
Objective-C
tree: 26343ab588

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
ActorKit.xcodeproj
ActorKit
license
test
.DS_Store
README.txt

README.txt

ActorKit extends NSObject to allow all objects to become actors. 

An actor has an os thread and a queue of incoming messages which it processes in first-in-first-out order.
Any message to the actor returns a "future" object which only blocks when it is accessed. These futures  automatically raise an exception in situations that would cause a deadlock.

example:

	// look ma, no state machine or callbacks - these spawn threads and return immediately
	
	NSURL *future1 = [[NSURL URLWithString:@"http://yahoo.com"] asActor];
	NSURL *future2 = [[NSURL URLWithString:@"http://google.com"] asActor];
	
	// now when we try to access the values, they block if the values aren't ready
	
	NSLog(@"request 1 returned %i bytes", (int)[future1 length]); 
	NSLog(@"request 2 returned %i bytes", (int)[future2 length]);


note:

	// you'll beed to add this method because dataWithContentsOfURL: is a class method but actors have to be instances
 
	@implementation NSURL (fetch)
	- (NSData *)fetch:sender { return [NSData dataWithContentsOfURL:self]; }
	@end

credits:

	Thanks to Mark Papadakis for help with figuring out how to properly use mutex conditions.
Something went wrong with that request. Please try again.