ProtoThreads
ProtoThreads
- Subject: ProtoThreads
- From: "Framework Labs." <email@hidden>
- Date: Thu, 5 Jan 2006 15:15:17 +0100
A programming concept called protothreads (http://www.sics.se/~adam/
pt/) might also help to ease Cocoa coding.
I created an Objective-C version of this library (http://
www.frameworklabs.de/protothreads.html) to evaluate the usefulness of
this idea.
The main benefit for Cocoa is that it allows you to wait for a
delegate-callback of an asynchronous Cocoa method right within your
body of code - reducing the spaghetti effect of having to distribute
your code over many callback handlers.
Below is a simple example demonstrating this:
- (void)run
{
PTThreadBegin;
...
ofts = [OBEXFileTransferServices withOBEXSession:...];
[ofts setDelegate:self];
OBEXError err = [otfs connectToObjectPushService];
...
// the following will wait until the delegate callback occurs.
// this waiting is done without blocking the RunLoop!
OBEXFileTransferServices *inServices;
OBEXError inError;
PTThreadWaitForInvocation(@selector
(fileTransferServicesConnectionComplete:error:), &inServices, &inError);
...
[ofts sendFile:file];
...
PTThreadEnd;
}
Cheers
marc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden