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: Alexander Cohen <email@hidden>
- Date: Tue, 27 Oct 2009 15:11:40 -0400
On Oct 27, 2009, at 2:04 PM, Jens Alfke wrote:
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.
100% agree with you, and that's what i would normally do. But
unfortunately, this time i must wait in the mainthread for the
callback. I know it's wrong, but this time i've gotta do it.
AC
_______________________________________________
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