Re: NSRunLoop looping more than once?
Re: NSRunLoop looping more than once?
- Subject: Re: NSRunLoop looping more than once?
- From: John Anderson <email@hidden>
- Date: Sun, 16 Mar 2003 23:51:25 -0500
Dear Chris,
Thank you for responding to my question. Your posts are critical to
those of us who are trying to learn the practical details of the
NSRunLoop paradigm.
Now, let us consider the second sentence of the NSRunLoop
documentation's Class Description
(
http://developer.apple.com/techpubs/macosx/Cocoa/Reference/Foundation/
ObjC_classic/Classes/NSRunLoop.html#//apple_ref/occ/cl/NSRunLoop):
"An NSRunLoop processes input for sources such as mouse and keyboard
events from the window system, NSPorts, NSTimers, and NSConnections."
To the extent that NSTimers are (as you have described): "a special
type," "not input" and "not literally 'input,'" I do not think that the
documentation is correct, but rather clearly misleading.
So, I have filed a bug report on the NSRunLoop documentation to which
Apple has assigned Problem ID#:3200069.
Truly Yours,
John Philip Anderson
Detroit Michigan USA
On Sunday, Mar 16, 2003, at 15:15 America/Detroit, Chris Kane wrote:
>
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.