• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
ProtoThreads
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: MainMenu
  • Next by Date: netService:didNotPublish: gets called with NSNetServicesErrorCode -65548
  • Previous by thread: Re: NSDictionary allKeys and allValues clarification?
  • Next by thread: netService:didNotPublish: gets called with NSNetServicesErrorCode -65548
  • Index(es):
    • Date
    • Thread