Re: NSRunLoop looping more than once?
Re: NSRunLoop looping more than once?
- Subject: Re: NSRunLoop looping more than once?
- From: Chris Kane <email@hidden>
- Date: Sun, 16 Mar 2003 12:15:17 -0800
Timers are not input in the sense that the documentation is using the
word in that sentence. They are a special type, and one of the things
that means is that they do not cause the run loop to return when they
occur. Timers aren't literally "input", so the documentation is
strictly correct. This has always been true of NSRunLoop; just the way
it was originally designed and written a decade ago. [Timers used to
be fired only as a side effect of calling limitDateForMode: in the most
fundamental of run loop looping algorithms, and runMode:beforeDate: was
a cover over that. -runMode:beforeDate: is "primitive" nowdays too, but
retains the same behavior it's always had, for compatibility.]
Another thing to keep in mind is that the "one thing" that might get
done might itself run the run loop, in a recursive activation (usually
in a different mode), waiting for something to happen. So the "one
thing" at the activation you started may actually encompass a lot of
time and "input" (say, running the open panel modally, if the "one
input" was cmd-O).
Finally, to avoid absolute starvation of some of the ... "input queues"
(for want of a better description), the run loop may occasionally need
to process two or a few input sources in one loop iteration.
Chris Kane
Cocoa Frameworks, Apple
On Tuesday, March 11, 2003, at 21:48, 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?
Truly yours,
John Philip Anderson
_______________________________________________
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.
_______________________________________________
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.