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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to