AnyEvent::Worker - Manage blocking task in external process
use AnyEvent 5; use AnyEvent::Worker; my $worker1 = AnyEvent::Worker->new( [ 'Actual::Worker::Class' => @init_args ] ); my $worker2 = AnyEvent::Worker->new( sub { return "Cb 1 @_"; } ); my $worker3 = AnyEvent::Worker->new( { class => 'Actual::Worker::Class2', new => 'create', # alternative constructor args => [qw(arg1 arg2)], } ); # Invoke method `test' on Actual::Worker::Class with arguments @args $worker1->do( test => @args , sub { return warn "Request died: $@" if $@; warn "Received response: @_"; }); # Just call callback, passed to worker2 with arguments @args $worker2->do( @args , sub { return warn "Request died: $@" if $@; warn "Received response: @_"; });
Simple stateless worker. On any do a sub sill be invoked with do arguments
do
Stateful, object-based worker. After fork, Class will we used, then instantiated with new(@new_args).
use
First argument to do will be interpreted as object method, rest -- as method arguments.
Same as previous, but allow to pass optional constructor name in new arg
new
When an unexpected error occurs (for ex: child process exited or killed) on_error callback will be invoked
on_error
Only for stateless worker.
Only for stateful worker.
Sets (or clears, with undef) the on_error handler.
undef
Sets (or clears, with undef) the database timeout. Useful to extend the timeout when you are about to make a really long query.
Executes worker code and execure the callback, when response is ready
Mons Anderson, <mons@cpan.org>
<mons@cpan.org>
This module based on Marc Lehmann's AnyEvent::DBI
Thanks to Vladimir Timofeev <vovkasm@cpan.org> for bugfixes and useful notes
<vovkasm@cpan.org>
To install AnyEvent::Worker, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AnyEvent::Worker
CPAN shell
perl -MCPAN -e shell install AnyEvent::Worker
For more information on module installation, please visit the detailed CPAN module installation guide.