Providing synch/asynch API
Providing synch/asynch API
- Subject: Providing synch/asynch API
- From: Andy Klepack <email@hidden>
- Date: Tue, 25 Mar 2008 09:05:17 -0700
- Acceptlanguage: en-US
- Thread-topic: Providing synch/asynch API
I have several methods for which I'd like to provide asynchronous and synchronous variants. These methods are not simple operations and have non-void return values. Is there a good model to follow in implementing this? I don't recall ever seeing a technique for this in any of the Cocoa documentation I've looked at.
In my mind I've got two options:
1. The synchronous version (fooSynch) is either the implementation or calls private implementation (_foo) on the same thread. The asynchronous version would detach a new thread to some method (threadedFood) that runs fooSynch and then takes care of calling callbacks, informing a delegate, etc.
2. The asynchronous version detaches a new thread to the implementation (_foo) that contains the operation and any necessary calls to callbacks, delegates, etc. The synchronous version wraps a call to the asynchronous version and somehow blocks the thread from returning until the asynchronous call completes. I'm not sure how to do this. I imagine it may involve installing ports in the run loop (over which the thread could communicate) and then running the run loop until the thread signals completion. That sounds a little too contrived.
I'm curious how people tackle this problem pre-Leopard and performSelector:onThread:withObject:waitUntilDone: API
Thanks,
-Andy
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden