Can I synchronously relinquish control to the event loop?
Marc Lehmann
schmorp at schmorp.de
Tue Feb 28 05:24:26 CET 2012
On Mon, Feb 27, 2012 at 06:04:12PM +0000, Dirk Koopman <djk at tobit.co.uk> wrote:
> Unfortunately, there seems to be no obvious way of making sure that
> nothing else is happening in AE when the timed loop happens and this
If with "nothing else" you mean "no outstanding events" then this is a
limitation in some event loops. AnyEvent offers an idle watcher which is
supposed to do just that, but it is emulated (using timers) on anything
but EV, Glib and Event, because it isn't implementable on the others.
> will, very occasionally, cause spurious error messages from places
> which don't seem to make much sense. Doesn't stop working, but I know
> I will get complaints when these messages are seen in the log.
Now I am not sure that "nothing else going on" has anything to do with
anyevent. What you describe sounds more as if that would be an internal
state in some library that took offense at being cleaned up. AnyEvent
itself being idle would not really have any meaning w.r.t. internal
application state, or in other words, how would AnyEvent know whether
*other* parts of your application are idle?
"idle" in AnyEvent simply means no other events seem to be outstanding. On
faster computers, AnyEvent will likely be idle more often, or less, and
this would not have any relationship to any state in any library using it.
> What I would like is a "timed" idle loop callback. A loop which is
> called whenever AE is truly idle, but only up to a maximum of so many
> per second.
That's easy, use a timer and an idle watcher:
my $cleanup;
sub do_cleanup {
$cleanup = AE::timer 1/20, 0, sub {
$cleanup = AE::idle sub {
do_cleanup ();
... idle code, not executed more than 20 times per second
};
};
}
> There need be no guarantee of being called the full (or even any) of
> that no of times, but AE *must* be truly idle.
You need to define what "truly idle" means, because I cannot imagine that
"truly idle" will fix any of your actual problems, because "idle" very
much depends on processing speed and load, and should not effect any
"it is valid to call cleanup now" in your application/library. That is,
why would it be valid to call the cleanup function more often on faster
computers, all else being equal?
You would probably have to ask your application/library when *it* is idle,
as opposed to when *anyevent* is idle, because your library thinks it
isn't idle, and likely this has little to do with when anyevent itself is
idle (or the event loop).
--
The choice of a Deliantra, the free code+content MORPG
-----==- _GNU_ http://www.deliantra.net
----==-- _ generation
---==---(_)__ __ ____ __ Marc Lehmann
--==---/ / _ \/ // /\ \/ / schmorp at schmorp.de
-=====/_/_//_/\_,_/ /_/\_\
More information about the anyevent
mailing list