Workaround for using synchronous modules in AnyEvent?

Zsbán Ambrus ambrus at math.bme.hu
Tue Apr 16 10:54:03 CEST 2013


On Tue, Apr 16, 2013 at 9:56 AM, Marc Lehmann <schmorp at schmorp.de> wrote:
> To make it work generically with event loops, you'd also need an
> event-based interface in zookeper, specifically:
>
> 1. you need to recreate the timer when the timeout target changes.
> 2. you need to recreate the I/O watchers when an fd is added or removed.
> 3. you need to recreate the I/O watchers when an fd is changed (but keeps the
>    same value).

Let me note that there's a fourth problem possible with such
interfaces as well: when the library doesn't trust your event loop.

I've met this when I tried to interface libcurl with libev.  The
libcurl interface satisfies the three points listed above: you can ask
libcurl to notify you whenever it wants you to change the timer or fd
watchers.  Libcurl, however, does its own timekeeping, and when the
timer watcher expires and you call libcurl back for that, it will
often believe that it's a little bit too early for the timeout still
and tells you to call it back 0 milliseconds later.  This leads to an
ugly busy loop.  The only workaround I have found is to add some small
delay when I set up the timer watcher.

Ambrus



More information about the anyevent mailing list