Re: Tight Runloop
Re: Tight Runloop
- Subject: Re: Tight Runloop
- From: Brian Smith <email@hidden>
- Date: Tue, 25 Sep 2007 06:56:47 -0600
On Sep 25, 2007, at 5:11 AM, Ricky McCrae wrote:
someFunction communicates with another object and needs to wait for a
callback so its occupying itself while it waits for the callback
like so;
do
{
[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
beforeDate:[NSDate dateWithTimeIntervalSinceNow: 2]];
}while(somecondition);
The callback is processed and the condition is met, the UI receives
updates
but mouse events are not processed.
Is this the correct way to 'occupy' a function or is this a great
example of
what not to do;
This doesn't seem to be a great way to do this as the main threads
run loop is already running, and you function just hijacked it and
started it running again. So, I think the behavior is undefined as
your seeing. Plus to get this working, I think you would have to not
re-run the run loop but take over event processing. What you are
trying to do suggest that someFunction should be run in a thread as
it will have its own run loop and won't block the rest of the
application while it waits. Since you have an event, the callback,
you might want to reconsider your design to be asynchronous, such
that you start the process in someFunction and then your callback
finishes it. So, ask yourself, why does someFunction need to wait?
Brian
_______________________________________________
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