Use of condvar in a callback of another event
Michael Fung
mike at 3open.org
Mon Mar 18 05:12:34 CET 2013
Thanks Marc! I will take a look at the Coro man pages.
Rgds,
Michael
On 3/18/2013 1:17 AM, Marc Lehmann wrote:
> On Sun, Mar 17, 2013 at 07:28:42PM +0800, Michael Fung <mike at 3open.org> wrote:
>> this sub will be called in a callback of another event. Will this
>> "nesting" have undesirable effects during high load?
>
> It might have undesirable effects under any load, which is why AnyEvent
> tries to catch it if it can.
>
> If you have trouble with the "don't call us, we call you" of event
> programming, you could try mixing it with Coro for the difficult parts, e.g.
>
> use Coro;
>
> async { # start new thread
> my $redis = ...;
> $redis->connect (...);
>
> $redis->hmget (..., Coro::rouse_cb);
> my @results = Coro::rouse_wait;
> };
>
> EV::loop;
>
> That also works with AnyEvent condvars:
>
> async { # start new thread
> $redis->hmget (..., my $cv = AE::cv);
> my @results = $cv->recv;
> };
>
> While you still can't block in an event loop callback with Coro, you can
> either do your stuff in another thread, running concurrently with the
> event loop, or start a thread from within an event loop callback.
>
> Coro automatically augments AnyEvent's condvars so that they can be used
> concurrently.
>
>> # $redis is an EV::Hiredis object already created
>
> Didn't know there was an EV::Hiredis module, interesting.
>
More information about the anyevent
mailing list