AnyEvent::ForkObject(3pm) | User Contributed Perl Documentation | AnyEvent::ForkObject(3pm) |
AnyEvent::ForkObject - Async access on objects.
use AnyEvent::ForkObject; use DBI; my $fo = new AnyEvent::ForkObject; $fo->do( module => 'DBI', method => 'connect', args => [ 'dbi:mysql...' ], cb => sub { my ($status, $dbh) = @_; $dbh->selectrow_array('SELECT ?', undef, 1 + 1, sub { my ($status, $result) = @_; print "$result\n"; # prints 2 }); } ); use AnyEvent::Tools qw(async_repeat); $dbh->prepare('SELECT * FROM tbl', sub { my ($status, $sth) = @_; $sth->execute(sub { my ($status, $rv) = @_; # fetch 30 rows async_repeat 30 => sub { my ($guard) = @_; $sth->fetchrow_hashref(sub { my ($status, $row) = @_; undef $guard; # do something with $row }); }; }); });
There are a lot of modules that provide object interface. Using the module You can use them in async mode.
Constructor. Creates an instance that contains fork jail.
Creates an object inside jail. It receives the following named arguments:
If "method" returns blessed object, it will provide all its methods in modified form. Each method will receive one or two additional arguments:
All objects provide additional method fo_attr to access their field. Example:
# set attribute $dbh->fo_attr(RaiseError => 1, sub { my ($status, $attr) = @_; ... }); # get attribute $dbh->fo_attr('RaiseError', sub { my ($status, $attr) = @_; ... });
Dmitry E. Oboukhov, <unera@debian.org>
Copyright (C) 2011 by Dmitry E. Oboukhov
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available.
The project is placed in my git repo: <http://git.uvw.ru/?p=anyevent-forkobject;a=summary>
2021-01-08 | perl v5.32.0 |