Where's AnyEvent's run_one_timeslice?

Mike Schilli office at perlmeister.com
Fri Aug 7 17:02:40 CEST 2015


Yeah, the problem with Curses::UI are its "modal" dialog boxes which pop up
when you call their function, then block until the user enters data and
confirms (all the while the event loop processes keystrokes and UI
updates), and tear down the UI on exit. Changing that to work
asynchronously through a different API is probably doable, but would
involve changing a morass of code, which is the reason I've held off on it
until now, but it seems there's no easy way out.

On Friday, August 7, 2015, djk <djk at tobit.co.uk> wrote:

> 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
>
> _______________________________________________
> anyevent mailing list
> anyevent at lists.schmorp.de
> http://lists.schmorp.de/mailman/listinfo/anyevent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/anyevent/attachments/20150807/f129f649/attachment.html>


More information about the anyevent mailing list