On Feb 1, 2010, at 8:57 AM, Jens Alfke wrote:

> 
> 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.

Actually, that points out a problem in our API. It would be beneficial if there 
was a version of writeToURL that automatically happened asynchronously from a 
background thread. Don't forget to log feature requests for stuff like this 
when you encounter problems like these.

-corbin

> 
> 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.)
> 

_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to