-
Notifications
You must be signed in to change notification settings - Fork 3
/
README
75 lines (57 loc) · 2.41 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
NAME
AnyEvent::Worker - Manage blocking task in external process
SYNOPSIS
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: @_";
});
CONSTRUCTOR
new $cb->($req), %args
Simple stateless worker. On any "do" a sub sill be invoked with "do"
arguments
new [ Class => @new_args ], %args
Stateful, object-based worker. After fork, Class will we "use"d, then
instantiated with new(@new_args).
First argument to "do" will be interpreted as object method, rest -- as
method arguments.
new { class => 'Class', args => \@new_args, new => 'constructor_method' }, %args
Same as previous, but allow to pass optional constructor name in "new"
arg
$args{on_error} = $cb->($worker,$error,$fatal,$file,$line)
When an unexpected error occurs (for ex: child process exited or killed)
"on_error" callback will be invoked
METHODS
do @args, $cb->($res)
Only for stateless worker.
do method => @args, $cb->($res)
Only for stateful worker.
METHODS
$worker->on_error ($cb->($worker, $filename, $line, $fatal))
Sets (or clears, with "undef") the "on_error" handler.
$worker->timeout ($seconds)
Sets (or clears, with "undef") the database timeout. Useful to
extend the timeout when you are about to make a really long query.
$worker->do ( @args, $cb->( $worker, @response ) )
Executes worker code and execure the callback, when response is
ready
AUTHOR
Mons Anderson, "<[email protected]>"
ACKNOWLEDGEMENTS
This module based on Marc Lehmann's AnyEvent::DBI
Thanks to Vladimir Timofeev "<[email protected]>" for bugfixes and useful
notes