AE::postpone degenerates into synchronous behavior, intended?
Marc Lehmann
schmorp at schmorp.de
Tue Jan 1 10:39:43 CET 2013
On Mon, Dec 31, 2012 at 05:33:28PM -0500, Michael Alan Dorman <mdorman at ironicdesign.com> wrote:
> I was working to patch Stevan Little's recently-released Promises
> library to always call callbacks asynchronously when running under
> AnyEvent.
I frankly don't understand what you mean with synchronous behaviour (maybe
it is indeed sleep, as the Darin remarked, as you never enter the event
loop).
However, postpone even in your example does exactly what it is documented
to do.
To me, it indeed looks as if you expect the event loop to run while you
call sleep, but for that, you need another thread to run the sleep - Darin
has made an example for this.
In general, the concept at work here would be "inversion of control flow" -
instead of calling something (like sleep), you need to arrange for a callback
to be invoked (AE::timer). In the first case, you do the event processing (by
callign sleep, which is like an event loop with only one timer), in the
second, you let the main program run the event loop and only arrange to get a
callback on events.
Coro can be used to invert the flow here, to some extent (sleep would
still block the whole process, but Coro::AnyEvent::sleep would not).
> The behavior I was hoping for can be achieved by replacing $postponement
> with:
I think you would need to explain what behaviour you actually want to
achieve, why you want this behaviour, and why you think postpone should
implement it.
> Looking at the code, it is clear to me why the difference in behavior
> exists, but seems to me that it if it is the behavior that is intended,
> it should be documented that nested calls to AE::postpone will behave
> synchronously...otherwise I'm happy to attempt to attempt a fix.
Since I don't know what you mean with synchronous, I can't say if that
behaviour is intended, but postpone has nothing to do with synchronous (or
not), it exists for the purpose of returning an object before destroying
it.
--
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