Re: waiting for async callback in main thread
Re: waiting for async callback in main thread
- Subject: Re: waiting for async callback in main thread
- From: Jens Alfke <email@hidden>
- Date: Tue, 27 Oct 2009 11:04:59 -0700
On Oct 27, 2009, at 10:40 AM, Alexander Cohen wrote:
Now, i would like to be able to wait for that callback on the main
thread like this:
[object addObserverForCallback]
... wait for callback ...
continue on processing with the state of the object
The only way i see i can do that is by running the NSRUnLoop myself
but if i understand correctly, it is wrong to do that. So i guess my
question is what is the corect way to wait in the main thread
without stopping the NSRunLoop?
It's actually wrong (in most cases) to wait in the main thread at all.
Blocking the main thread prevents events from being handled and
results in the dreaded beachball cursor.
What you should be doing instead is structuring your code
asynchronously. Set up the callbacks, then keep the app running
normally and handle the callbacks when they occur. It's definitely a
bit more complex to code this way, but it keeps your app responsive
while avoiding the greater complexity of multi-threading.
—Jens_______________________________________________
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