On Feb 1, 2010, at 7:20 AM, Kyle Sluder wrote:

> So in your override of -writeToURL:…, spin off the background thread like I 
> suggested, then set up your UI, and then start running the runloop in a 
> special modal mode until your background thread is done.

Nested runloops like this are usually a "code smell", an indication that you're 
trying to shoehorn asynchronous code into a synchronous caller, and should 
instead refactor the calling code to be async too. However, if you're 
implementing NSDocument's abstract save functionality, you can't do a lot about 
that.

Pay attention to Kyle's advice to use "a special modal mode". If you run the 
runloop in a normal mode, then your app can handle incoming events while in 
this loop and dispatch them to your code — this often leads to unexpected 
re-entrancy that can cause bizarre and hard-to-debug problems. (It's happened 
to me more than once.) Nowadays I always make sure that, if I have to use a 
nested runloop, I make up my own unique mode name to run it in.

(BTW, it seems a little odd to me that it takes so long to save documents in 
your app. Have you tried profiling your save implementation to see if it can be 
made faster? Most apps save nearly instantaneously.)

—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