discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about NSRunLoop -runUntilDate:


From: Richard Frith-Macdonald
Subject: Re: Question about NSRunLoop -runUntilDate:
Date: Tue, 2 Aug 2005 12:15:06 +0100


On 2 Aug 2005, at 07:52, Chris Vetter wrote:


On Mon, 1 Aug 2005 12:45:10 Richard Frith-Macdonald wrote:
[...]

No ... runloops are meant to be thread-local, and it's not safe to
monitor a runloop running in one thread from an other thread.
If you want a notification when there are no more inputs for a
runloop, you can just use -runUntilDate:

[...]

That wouldn't work, because -runUntilDate: works differently from what I expected. Instead of just setting the date when to stop running, it will
actually *wait* (aka 'block') until the given date has been reached.

No, that's not what the method does.
The -runUntilDate: method waits for the date or for there to be no more input sources ... whichever comes FIRST. This is exactly what (as I understood it) you originally said you wanted:

# I need to create a runloop that's supposed to run for X minutes. Naturally,
# -runUntilDate: comes to mind. So far, so good.
#
# My question is whether there is an appropriate method to get some/ any kind # of 'notification' that the runloop has stopped. I do not really care whether # it stops because all input sources have been removed or the limitDate has # been reached. I just need to send (or rather receive) a 'note' that the
# runloop stopped.


Nevertheless thanks for your hints. Based on that I did figure out how to solve the problem by just adding another timer to the runloop that fires at a certain time, calling a method that will stop the runloop and sending the
note. Easy as that :-}

Setting a timer is the correct way to to something at a particular time ... however it won't solve the problem you specified ... how to get a notification when there are no more input sources in the runloop ... since it triggers the notification irrespective of the number of input sources still in the loop.

It sounds like what you actually want/need is to terminate the runloop at a particular time even if there are input sources waiting in it, and have found the best way to do that.

BTW how do you terminate your runloop? The only way I can think of is to remove all input sources ... or have a loop calling - runMode:beforeDate: repeatedly and checking a flag after each run of the loop (with the timer setting that flag).






reply via email to

[Prev in Thread] Current Thread [Next in Thread]