Tight Runloop
Tight Runloop
- Subject: Tight Runloop
- From: "Ricky McCrae" <email@hidden>
- Date: Tue, 25 Sep 2007 21:11:39 +1000
Hey,
I have some code that is getting caught in a tight in a tight run loop - it
fulfills its function but locks the UI.
The work needs to be performed is not thread safe and therefor needs to be
performed on the current thread.
Because the code is pseudo asynchronous it is scheduled to run on the
current runloop like so;
[object performSelector:@selector ( someFunction: ) withObject:nil
afterDelay:0.0];
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.
It is possible to refactor everything and have the callback respond through
the chain to the main controller, but this does increase the complexity
somewhat - a linear approach is easier to follow;
Is this the correct way to 'occupy' a function or is this a great example of
what not to do;
cheers
_______________________________________________
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