Where's AnyEvent's run_one_timeslice?

djk djk at tobit.co.uk
Fri Aug 7 16:39:31 CEST 2015


On 07/08/15 05:32, Mike Schilli wrote:
> While porting a module from POE to AnyEvent, I found myself in the
> unfortunate situation of having to deal with a synchronous (aka
> blocking) function that I have no control over and can't easily
> redesign.
>
> POE solves the problem by inverting control, by calling back into the
> event loop until a condition is met, like:
>
>      sub blocking_function {
>         while( !condition ) {
>             POE::Kernel->run_one_timeslice();
>         }
>      }
>
> Since I can't block in a callback in AnyEvent (via a condvar or even
> via Coro), is there a similar way I can call back into the event loop
> to run a slice and check back regularly if my condition is met, which
> is when I exit my blocking function?
>
> For the record, this is about porting Curses::UI to AnyEvent, there's
> a deja-vu here, and running the POE version in AnyEvent worked ok for
> a while, but I'd rather have a native port:
>

So how does Mojo::IOLoop->next_tick do it then?

Also: what is actually blocking in Curses::UI? Because it *is* possible 
to operate Curses (not ::UI) in a non-blocking environment.  The getch() 
method is (or can be made to be) non-blocking.

Dirk



More information about the anyevent mailing list