Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Simplified API for testing AnyEvent-related code

by Dallaylaen (Hermit)
on Sep 14, 2012 at 08:42 UTC ( #993681=perlquestion: print w/replies, xml ) Need Help??
Dallaylaen has asked for the wisdom of the Perl Monks concerning the following question:

When developing (and therefore writing tests and fire-and-forget scripts) for AnyEvent I routinely end up with a boilerplate like this:
my $cv = AnyEvent->condvar; my $timer = AnyEvent->timer( after => 10, cb => sub { $cv->croak("Time +out"); }; do_something( on_success => sub{ $cv->send(@_); }, on_error => sub{ $cv->croak(shift); }, ); my $result = $cv->recv(); undef $timer; analyze_do_something( $result );
I finally got fed up with it and wrote a module (after asking a local mailing list) with the following interface:
my $result = ae_recv { do_something( on_success => ae_send, on_error => ae_croak, ); } 10; # timeout analyze_do_something( $result );
So, my questions would be:

1) Is there such a module already? I haven't found one, but...

2) Is there really a need for such a module?

3) If so, how should I name it? I came up with AnyEvent::AdHoc, but that still isn't clear enough. AnyEvent::Test seems misleading (it's not test-only, and doesn't test AnyEvent itself) and AnyEvent::Simple/Easy seem too broad (besides, AnyEvent doesn't seem easy even with a nice wrapper).

UPDATE: I released the code in question as AE::AdHoc. See

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://993681]
Approved by Athanasius
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2018-04-22 06:42 GMT
Find Nodes?
    Voting Booth?