Re: NSRunLoop looping more than once?
Re: NSRunLoop looping more than once?
- Subject: Re: NSRunLoop looping more than once?
- From: Julien Jalon <email@hidden>
- Date: Sun, 16 Mar 2003 17:16:35 +0100
On mercredi, mars 12, 2003, at 06:48 Europe/Paris, John Anderson wrote:
Dear List,
According to Apple's documention, calling runMode: beforeDate: on
NSRunLoop "runs the loop once" and "returns after ... the first input
is processed.
So with the following code:
myTimer = [NSTimer timerWithTimeInterval:timeInterval target:self
selector:@selector(myMethod) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:myTimer
forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
beforeDate:[NSDate distantFuture]];
I would expect to have "myMethod" called once when "myTimer" fires and
then control to passed on done the line.
However, this is not what happens. In fact, the NSRunLoop appears to
loop indefinitely and calls "myMethod" every time "myTimer" fires, as
if I had called run or runUntilDate: on it.
Is this supposed to happen?
If so, then what do "loop once" and "return after ... the first input
in processed" really mean?
I found this exact same problem while implementing some sort of a Time
out. A timer seems not to trigger the "run loop handled a source"
trick. I think we can consider it a bug but you have to use a
workaround here if you want your call to runMod:beforeDate: to return
even after a timer firing:
- (void)timerFired:(NSTimer *)aTimer {
// do all your work
CFRunLoopStop([[NSRunLoop currentRunLoop] getCFRunLoop]);
}
--
Julien Jalon
http://www.julien-jalon.org/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.