view release on metacpan or search on metacpan
lib/AnyEvent/FIFO.pm view on Meta::CPAN
90919293949596979899AnyEvent::FIFO - Simple FIFO Callback Dispatch
=head1 SYNOPSIS
my $fifo = AnyEvent::FIFO->new(
max_active => 1, # max "concurrent" callbacks to execute per slot
);
# send to the "default" slot
$fifo->push( \&callback, @args );
lib/AnyEvent/FIFO.pm view on Meta::CPAN
view all matches for this distribution
114115116117118119120121122123124125126127128129130131132133134135136=head1 DESCRIPTION
AnyEvent::FIFO is a simple FIFO queue to dispatch events in order.
If you use regular watchers and register callbacks from various places in
your program, you're not necessarily guaranteed that the callbacks will be
executed in the order that you expect. By using this module, you can
register callbacks and they will be executed in that particular order.
=head1 METHODS
=head2 new
=over 4
=item max_active => $number
Number of concurrent callbacks to be executed B<per slot>.
=item cv => $cv
Instance of L<AnyEvent condvar|AnyEvent/"CONDITION VARIABLES">. AnyEvent::FIFO will create one for you if this is not provided.
view release on metacpan or search on metacpan
lib/AnyEvent/FTP/Role/Event.pm view on Meta::CPAN
view all matches for this distribution
949596979899100101102103104105106107108109110111112113114115116117118119120=head1 DESCRIPTION
This role provides a uniform even callback mechanism for classes in L<AnyEvent::FTP>.
You declare events by using the C<define_events> method. Once declared
you can use C<on_>I<event_name> to add a callback to a particular event
and C<emit> to trigger those callbacks.
=head1 METHODS
=head2 define_events
__PACKAGE__->define_events( @list_of_event_names );
This is called within the class package to declare the event names for all
events used by the class. It creates methods of the form C<on_>I<event_name>
which can be used to add callbacks to events.
=head2 emit
$obj->emit($event_name, @arguments);
This calls the callbacks associated with the given C<$event_name>.
It will pass to that callback the given C<@arguments>.
=head1 SEE ALSO
=over 4
view release on metacpan or search on metacpan
FastPing.pm view on Meta::CPAN
view all matches for this distribution
8182838485868788899091=head1 THE AnyEvent::FastPing CLASS
The AnyEvent::FastPing class represents a single "pinger". A "pinger"
comes with its own thread to send packets in the background, a rate-limit
machinery and separate idle/receive callbacks.
The recommended workflow (there are others) is this: 1. create a new
AnyEvent::FastPing object 2. configure the address lists and ranges to
ping, also configure an idle callback and optionally a receive callback
3. C<start> the pinger.
view release on metacpan or search on metacpan
lib/AnyEvent/Finger.pm view on Meta::CPAN
view all matches for this distribution
119120121122123124125126127128=head2 finger_server
my $server = finger_server $callback, \%options;
Start listening to finger callbacks and call the given callback
for each request. See L<AnyEvent::Finger::Server> for details
on the options and the callback.
=head1 CAVEATS
view release on metacpan or search on metacpan
view all matches for this distribution
598599600601602603604605606607608=back
=head1 EXCEPTIONS
The same "policy" as with L<AnyEvent::Fork::RPC> applies - exceptions
will not be caught, and exceptions in both worker and in callbacks causes
undesirable or undefined behaviour.
=head1 SEE ALSO
L<AnyEvent::Fork>, to create the processes in the first place.
view release on metacpan or search on metacpan
view all matches for this distribution
847848849850851852853854855856857to
send
an error message just
before
exiting, or
when
you want to ensure
replies timely reach the parent
before
starting a long blocking operation.
In these cases, you can call this function to flush any outstanding reply
data to the parent. This is done blockingly, so
no
requests will be
handled and
no
event callbacks will be called.
For example, you could wrap your request function in a C<
eval
> block and
report the exception string back to the
caller
just
before
exiting:
sub
req {
view release on metacpan or search on metacpan
view all matches for this distribution
147148149150151152153154155156157
my
$timeout
;
$timeout
= AE::timer 1,
0
=>
sub
{
undef
$timeout
;
$cv
->
send
};
$cv
->
recv
;
ok
$dont_call_if_destroyed
,
"Don't touch callbacks if destroyed"
;
ok
$timeout
,
"Timeout wasn't reached"
;
}
package
FO_Test;
view release on metacpan or search on metacpan
1617181920212223242526It properly quotes your commands and parses the data structures returned
by GDB.
At the moment, it's in an early stage of development, so expect changes,
and, over
time
, further features (such as breakpoint-specific callbacks
and so on).
=head1 EXAMPLE PROGRAM
To get you started, here is an example program that runs F</bin/ls>,
495496497498499500501502503504Like C<cmd>, but blocks execution
until
the command
has
been executed, and
returns the results
if
sucessful. Croaks
when
GDB returns
with
an error.
This is purely a convenience method
for
small scripts: since it blocks
execution using a condvar, it is not suitable to be used inside callbacks
or modules.
That is,
unless
L<Coro> is used -
with
Coro, you can run multiple
C<cmd_sync> methods concurrently form multiple threads,
with
no
issues.
view all matches for this distribution
677678679680681682683684685686687Any callback specified as C<on_EVENTNAME> parameter to the constructor.
=back
You can change callbacks dynamically by simply replacing the corresponding
C<on_XXX> member in the C<$gdb> object:
$gdb->{on_event} = sub {
# new event handler
};
view release on metacpan or search on metacpan
view all matches for this distribution
45464748495051525354argument is missing then C<localhost:2947> will be used.
If the connection cannot be established, then it will retry every
second. Otherwise, the connection is put into watcher mode.
You can specify various configuration parameters, most of them callbacks:
=over 4
=item host => $hostname
view release on metacpan or search on metacpan
lib/AnyEvent/Gearman/Client.pm view on Meta::CPAN
141142143144145146147148149150151152153The namespace is currently implemented as a simple tab separated concatenation of the prefix and the function name.
=back
=head2 add_task($function, $workload, %callbacks)
Start new job and wait results in C<%callbacks>
$gearman->add_task(
$function => $workload,
on_complete => sub {
my $result = $_[1],
lib/AnyEvent/Gearman/Client.pm view on Meta::CPAN
157158159160161162163164165166
},
);
C<
$function
> is a worker function name, and C<
$workload
> is a data that will be passed to worker.
C<
%callbacks
> is set of callbacks called by job events. Available callbacks are:
=over 4
=item on_complete => $cb->($self, $result)
lib/AnyEvent/Gearman/Client.pm view on Meta::CPAN
view all matches for this distribution
191192193194195196197198199200201202203204=back
You should to set C<on_complete> and C<on_fail> at least.
=head2 add_task_bg($function, $workload, %callbacks)
Starts a new background job. The parameters are the same as
L<add_task($function, $workload, %callbacks)|add_task()>, but the only
callback that is called is C<on_created>.
$gearman->add_task_bg(
$function => $workload,
on_created => sub {
view release on metacpan or search on metacpan
xt/author/pod_spelling_system.t view on Meta::CPAN
view all matches for this distribution
4243444546474849505152TODO
filename
filenames
login
callback
callbacks
standalone
VMS
hostname
hostnames
TCP
view release on metacpan or search on metacpan
view all matches for this distribution
56789101112131415Makefile.PL
README
dist.ini
lib/AnyEvent/HTTP/LWP/UserAgent.pm
t/async.t
t/callbacks.t
t/invalid_host.t
t/main.t
t/release-pod-syntax.t
t/request_content_ref.t
t/response_content_cb.t
view release on metacpan or search on metacpan
view all matches for this distribution
93949596979899100101102
- bump AnyEvent dependency version (reported by Richard Harris).
2.1 Thu Feb 24 13:11:51 CET 2011
- the keepalive and persistent parameters were actually named
differently in the code - they now work as documented.
- fix a bug where callbacks would sometimes never be called
when
the request timeout is near or below the persistent connection
timeout (testcase by Cindy Wang).
- destroying the guard would have
no
effect
when
a request was
recursing or being retired.
view release on metacpan or search on metacpan
benchmark.pl view on Meta::CPAN
view all matches for this distribution
4041424344454647484950#starting requests
for
( 1 ..
$concurency
) {
add_request(
$_
,
$url
);
}
$cv
->
recv
;
# begin receiving message and make callbacks magic ;)
end_bench();
# call the end
#subs
sub
parse_command_line {
if
(not
defined
@ARGV
)
view release on metacpan or search on metacpan
lib/AnyEvent/HTTPD/ExtDirect.pm view on Meta::CPAN
82838485868788899091sub
run {
my
(
$self
) =
@_
;
my
$config
=
$self
->config;
$self
->set_callbacks(
api_path
=>
$config
->api_path,
router_path
=>
$config
->router_path,
poll_path
=>
$config
->poll_path,
);
lib/AnyEvent/HTTPD/ExtDirect.pm view on Meta::CPAN
view all matches for this distribution
235236237238239240241242243244245246247248249250
$self
->stop_request;
}
### PUBLIC INSTANCE METHOD ###
#
# Register the callbacks for Ext.Direct handlers.
# This effectively "primes" the server but does not make it
# enter a blocking wait.
#
sub
set_callbacks {
my
(
$self
,
%arg
) =
@_
;
my
$config
=
$self
->config;
my
$api_path
=
$arg
{api_path} ||
$config
->api_path;
view release on metacpan or search on metacpan
lib/AnyEvent/HTTPD/Router.pm view on Meta::CPAN
125126127128129130131132133134135136137This module aims to add as little as possible overhead to it
while
still being
flexible and extendable. It requires the same little dependencies that
L<AnyEvent::HTTPD> uses.
The dispatching
for
the routes happens first. If
no
route could be found, or you
do
not stop further dispatching
with
C<stop_request()> the registered callbacks
upgrade from callbacks to routes step by step.
Routes support http methods, but custom methods
L<https://cloud.google.com/apis/design/custom_methods> can also be used. You
don't need to, of course ;-)
lib/AnyEvent/HTTPD/Router.pm view on Meta::CPAN
view all matches for this distribution
239240241242243244245246247248249250251=item * no_route_found => $request
When the dispatcher can not find a route that matches on your request, the
event C<no_route_found> will be emitted.
In the case that routes and callbacks (C<reg_cb()>) for paths as used with
C<AnyEvent::HTTPD> are mixed, keep in mind that that C<no_route_found> will
happen before the other path callbacks are executed. So for a
C<404 not found> handler you could do
$httpd->reg_cb('' => sub {
my ( $httpd, $req ) = @_;
$req->respond( [ 404, 'not found', {}, '' ] );
view release on metacpan or search on metacpan
lib/AnyEvent/HTTPD.pm view on Meta::CPAN
8485868788899091929394The L<AnyEvent::HTTPD> class inherits directly from
L<AnyEvent::HTTPD::HTTPServer> which inherits the event callback interface from
L<Object::Event>.
Event callbacks can be registered via the L<Object::Event> API (see the
documentation of L<Object::Event>
for
details).
For a list of available events see below in the I<EVENTS> section.
=over 4
lib/AnyEvent/HTTPD.pm view on Meta::CPAN
view all matches for this distribution
162163164165166167168169170171=item allowed_methods => $arrayref
This parameter sets the allowed HTTP methods for requests, defaulting to GET,
HEAD and POST. Each request received is matched against this list, and a
'501 not implemented' is returned if no match is found. Requests using
disallowed handlers will never trigger callbacks.
=back
=cut
view release on metacpan or search on metacpan
lib/AnyEvent/Handle/UDP.pm view on Meta::CPAN
view all matches for this distribution
393394395396397398399400401402=head2 wtimeout
If non-zero, then these enables an "inactivity" timeout: whenever this many seconds pass without a successful read or write on the underlying file handle (or a call to C<timeout_reset>), the on_timeout callback will be invoked (and if that one is mis...
There are three variants of the timeouts that work independently of each other, for both read and write (triggered when nothing was read OR written), just read (triggered when nothing was read), and just write: timeout, rtimeout and wtimeout, with co...
Note that timeout processing is active even when you do not have any outstanding read or write requests: If you plan to keep the connection idle then you should disable the timeout temporarily or ignore the timeout in the corresponding on_timeout cal...
Calling C<clear_timeout> (or setting it to zero, which does the same) disables the corresponding timeout.
view release on metacpan or search on metacpan
lib/AnyEvent/Handle/Writer.pm view on Meta::CPAN
view all matches for this distribution
46474849505152535455
$hdl
->push_sendfile(
'/path/to/file'
, 1024);
=head1 RATIONALE
We have great l<AnyEvent::Handle>. But it have only raw write queue. This module extends it with
callbacks in write queue and adds a C<push_sendfile()> call, which would be processed at correct time
=head1 METHODS
=cut
view release on metacpan or search on metacpan
lib/AnyEvent/I3.pm view on Meta::CPAN
226227228229230231232233234235236237238on_error
=>
sub
{
my
(
$hdl
,
$fatal
,
$msg
) =
@_
;
delete
$self
->{ipchdl};
$hdl
->destroy;
my
$cb
=
$self
->{callbacks};
# Trigger all one-time callbacks with undef
for
my
$type
(
keys
%{
$cb
}) {
next
if
(
$type
&
$event_mask
) ==
$event_mask
;
$cb
->{
$type
}->();
delete
$cb
->{
$type
};
}
lib/AnyEvent/I3.pm view on Meta::CPAN
268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332}
sub
_handle_i3_message {
my
(
$self
,
$type
,
$payload
) =
@_
;
return
unless
defined
(
$self
->{callbacks}->{
$type
});
my
$cb
=
$self
->{callbacks}->{
$type
};
$cb
->(decode_json
$payload
);
return
if
(
$type
&
$event_mask
) ==
$event_mask
;
# If this was a one-time callback, we delete it
# (when connection is lost, all one-time callbacks get triggered)
delete
$self
->{callbacks}->{
$type
};
}
=head2 $i3->subscribe(\%callbacks)
Subscribes to the given event types. This function awaits a hashref with the
key being the name of the event and the value being a callback.
my %callbacks = (
workspace => sub { say "Workspaces changed" }
);
if ($i3->subscribe(\%callbacks)->recv->{success}) {
say "Successfully subscribed";
}
The special callback with name C<_error> is called when the connection to i3
is killed (because of a crash, exit or restart of i3 most likely). You can
use it to print an appropriate message and exit cleanly or to try to reconnect.
my %callbacks = (
_error => sub {
my ($msg) = @_;
say "I am sorry. I am so sorry: $msg";
exit 1;
}
);
$i3->subscribe(\%callbacks)->recv;
=cut
sub
subscribe {
my
(
$self
,
$callbacks
) =
@_
;
# Register callbacks for each message type
for
my
$key
(
keys
%{
$callbacks
}) {
if
(!
exists
$events
{
$key
}) {
warn
"Could not subscribe to event type '$key'."
.
" Supported events are "
.
join
(
" "
,
sort
keys
%events
), $/;
next
;
}
my
$type
=
$events
{
$key
};
$self
->{callbacks}->{
$type
} =
$callbacks
->{
$key
};
}
$self
->message(TYPE_SUBSCRIBE, [
keys
%{
$callbacks
} ])
}
=head2 $i3->message($type, $content)
Sends a message of the specified C<type> to i3, possibly containing the data
lib/AnyEvent/I3.pm view on Meta::CPAN
view all matches for this distribution
360361362363364365366367368369370371372373
my
$cv
= AnyEvent->condvar;
# We don’t preserve the old callback as it makes no sense to
# have a callback on message reply types (only on events)
$self
->{callbacks}->{
$type
} =
sub
{
my
(
$reply
) =
@_
;
$cv
->
send
(
$reply
);
undef
$self
->{callbacks}->{
$type
};
};
$cv
}
view release on metacpan or search on metacpan
t/01-simple.t view on Meta::CPAN
1011121314151617181920
client
=>
sub
{
my
$port
=
shift
;
my
$cv
= AE::cv();
my
$cv_join
= AE::cv();
my
@callbacks
= (
# sub {
# my ($channel, $raw) = @_;
# my $who = $raw->{prefix} || '*';
# my $channel_name = $raw->{params}->[0];
# my $msg = $raw->{params}->[1];
t/01-simple.t view on Meta::CPAN
view all matches for this distribution
56575859606162636465666768'irc_privmsg'
=>
sub
{
# use Data::Dumper; warn Dumper($_[1]);
},
'publicmsg'
=>
sub
{
my
(
$irc
,
$channel
,
$raw
) =
@_
;
my
$cb
=
shift
@callbacks
;
$cb
->(
$channel
,
$raw
);
if
(
scalar
(
@callbacks
) == 0) {
$cv
->
send
();
}
},
'join'
=>
sub
{
ok 1,
'join event'
;
view release on metacpan or search on metacpan
lib/AnyEvent/IRC/Client.pm view on Meta::CPAN
view all matches for this distribution
9939949959969979989991000100110021003IRC command.
If C<
$coderef
> was
given
and is a code reference, it will called
each
time
a
C<
$ctcp_command
> is received, this is useful
for
eg. CTCP PING reply
generation. The arguments will be the same arguments that the C<ctcp> event
callbacks get. (See also C<ctcp> event description above). The
return
value of
the called subroutine should be a list of arguments
for
C<encode_ctcp>.
Currently you can only configure one auto-reply per C<
$ctcp_command
>.
Example:
view release on metacpan or search on metacpan
xt/author/pod_spelling_system.t view on Meta::CPAN
view all matches for this distribution
4243444546474849505152TODO
filename
filenames
login
callback
callbacks
standalone
VMS
hostname
hostnames
TCP
view release on metacpan or search on metacpan
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
18091810181118121813181418151816181718181819
offset
=> 3,
# downsample result to another database, retention policy and measurement
into
=>
'otherdb."default".cpu_load_per5m'
,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to select data: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
18551856185718581859186018611862186318641865
duration
=>
'7d'
,
shard_duration
=>
'30m'
,
replication
=> 3,
name
=>
'oneweek'
,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to create database: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
18821883188418851886188718881889189018911892
q =>
"DROP DATABASE mydb"
,
# or query created from arguments
database
=>
"mydb"
,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to drop database: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
19111912191319141915191619171918191919201921
where
=>
q{host = 'server02'}
,
# multiple measurements can also be specified
measurements
=> [
qw( cpu_load cpu_temp )
],
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to drop measurement: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
19381939194019411942194319441945194619471948
# or query created from arguments
measurement
=>
'cpu_load'
,
where
=>
q{host = 'server02' AND time < '2016-01-01'}
,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to drop measurement: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
19641965196619671968196919701971197219731974
q =>
"DROP MEASUREMENT cpu_load"
,
# or query created from arguments
measurement
=>
'cpu_load'
,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to drop measurement: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
20362037203820392040204120422043204420452046
q =>
"DROP SHARD 1"
,
# or query created from arguments
id
=> 1,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to drop measurement: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
20782079208020812082208320842085208620872088$cv
= AE::cv;
$db
->kill_query(
id
=> 36,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to kill query: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
21082109211021112112211321142115211621172118
duration
=>
'1d'
,
shard_duration
=>
'168h'
,
replication
=> 1,
default
=> 0,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to create retention policy: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
21402141214221432144214521462147214821492150
duration
=>
'1d'
,
shard_duration
=>
'12h'
,
replication
=> 1,
default
=> 1,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to alter retention policy: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
21662167216821692170217121722173217421752176
# or query created from arguments
name
=>
"last_day"
,
database
=>
"mydb"
,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to drop retention policy: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
22082209221022112212221322142215221622172218
q =>
"SHOW RETENTION POLICIES ON mydb"
,
# or query created from arguments
database
=>
'mydb'
,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to list retention policies: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
22512252225322542255225622572258225922602261
order_by
=>
'region'
,
limit
=> 10,
offset
=> 3,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to list series: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
22872288228922902291229222932294229522962297
order_by
=>
'region'
,
limit
=> 10,
offset
=> 3,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to list measurements: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
23202321232223232324232523262327232823292330
where
=>
q{host = 'server02'}
,
limit
=> 10,
offset
=> 3,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to list tag keys: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
23602361236223632364236523662367236823692370
keys
=> [
qw( "host" "region" )
],
limit
=> 10,
offset
=> 3,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to list tag values: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
23952396239723982399240024012402240324042405
q =>
"SHOW FIELD KEYS FROM cpu_load"
,
# or query created from arguments
measurement
=>
'cpu_load'
,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to list field keys: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
24312432243324342435243624372438243924402441
# or query created from arguments
username
=>
'jdoe'
,
password
=>
'mypassword'
,
all_privileges
=> 1,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to create user: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
24582459246024612462246324642465246624672468
# or query created from arguments
username
=>
'jdoe'
,
password
=>
'otherpassword'
,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to set password: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
25112512251325142515251625172518251925202521
access
=>
'ALL'
,
# or to grant cluster administration privileges
all_privileges
=> 1,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to grant privileges: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
25362537253825392540254125422543254425452546
q =>
"SHOW GRANTS FOR jdoe"
,
# or query created from arguments
username
=>
'jdoe'
,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to list users: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
25712572257325742575257625772578257925802581
access
=>
'WRITE'
,
# or to revoke cluster administration privileges
all_privileges
=> 1,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to revoke privileges: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
25962597259825992600260126022603260426052606
q =>
"DROP USER jdoe"
,
# or query created from arguments
username
=>
'jdoe'
,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to drop user: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
26292630263126322633263426352636263726382639
name
=>
'per5minutes'
,
every
=>
'10s'
,
for
=>
'2m'
,
query
=>
'SELECT MEAN(value) INTO "cpu_load_per5m" FROM cpu_load GROUP BY time(5m)'
,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to create continuous query: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
26552656265726582659266026612662266326642665
# or query created from arguments
database
=>
'mydb'
,
name
=>
'per5minutes'
,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to drop continuous query: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
27152716271727182719272027212722272327242725
mode
=>
"ANY"
,
destinations
=> [
],
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to create subscription: @_"
);
}
);
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
view all matches for this distribution
27692770277127722773277427752776277727782779
# or query created from arguments
name
=>
q{"alldata"}
,
database
=>
q{"mydb"}
,
rp
=>
q{"default"}
,
# callbacks
on_success
=>
$cv
,
on_error
=>
sub
{
$cv
->croak(
"Failed to drop subscription: @_"
);
}
);
view release on metacpan or search on metacpan
lib/AnyEvent/Inotify/EventReceiver.pm view on Meta::CPAN
view all matches for this distribution
4445464748495051525354=head2 handle_create
Called when a new file, C<$file>, appears in the watched directory.
If it's a directory, we automatically start watching it and calling
callbacks for files in that directory, still relative to the original
directory. C<IN_CREATE>.
=head2 handle_access($file)
Called when C<$file> is accessed. C<IN_ACCESS>.
view release on metacpan or search on metacpan
lib/AnyEvent/JSONRPC/Lite/Client.pm view on Meta::CPAN
5859606162636465666768
my
$id
= 0;
sub
{ ++
$id
};
},
);
has
_callbacks
=> (
is
=>
'ro'
,
isa
=>
'HashRef'
,
lazy
=> 1,
default
=>
sub
{ {} },
);
lib/AnyEvent/JSONRPC/Lite/Client.pm view on Meta::CPAN
view all matches for this distribution
126127128129130131132133134135136137138139140141
}
else
{
push
@{
$self
->_request_pool },
$request
;
}
$self
->_callbacks->{
$request
->{id} } = AnyEvent->condvar;
}
sub
_handle_response {
my
(
$self
,
$res
) =
@_
;
my
$d
=
delete
$self
->_callbacks->{
$res
->{id} };
unless
(
$d
) {
warn
q/Invalid response from server/
;
return
;
}
view release on metacpan or search on metacpan
lib/AnyEvent/JSONRPC/HTTP/Server.pm view on Meta::CPAN
view all matches for this distribution
155156157158159160161162163164165Listening port. Default to
'8080'
.
=back
=head2 reg_cb (%callbacks)
Register JSONRPC methods.
$server->reg_cb(
echo => sub {
view release on metacpan or search on metacpan
lib/AnyEvent/KVStore/Hash.pm view on Meta::CPAN
414243444546474849505152Each kvstore here
has
its own keyspace and watch list.
=head2 Watch Behavior
C<AnyEvent::KVStore::Hash> allows for unlimited watches to be set up, and
because this key/value store is private, the callbacks are handled synchronous
to the writes. If you want asynchronous callbacks, you can use the
C<unblock_sub> function from L<Coro>.
Watches are currently indexed by the first letter of the prefix, or if no
prefix is given, an empty string. Watches are then checked (and executed)
in order of:
lib/AnyEvent/KVStore/Hash.pm view on Meta::CPAN
view all matches for this distribution
8889909192939495969798=head2 watch
In this module, watches are run synchronously, not via AnyEvent's event loop.
If you wish to use AnyEvent's event loop, use condition variables with
callbacks set and C<send> them.
=cut
sub
read
($$) {
my
(
$self
,
$key
) =
@_
;
view release on metacpan or search on metacpan
lib/AnyEvent/Lingr.pm view on Meta::CPAN
423424425426427428429430431432
warn
$res
->{message}->{id};
});
=head1 CALLBACKS
This module supports following three callbacks:
=over
=item * on_error->($msg)
lib/AnyEvent/Lingr.pm view on Meta::CPAN
435436437438439440441442443444=item * on_event->($event)
=back
All callbacks can be set by accessor:
$lingr->on_error(sub { ... });
Or by constructor:
lib/AnyEvent/Lingr.pm view on Meta::CPAN
view all matches for this distribution
448449450451452453454455456457
on_error
=>
sub
{ ... },
);
=head2 on_error->($msg)
Error callbacks.
C<$msg> is error message. If this message is form of "\d\d\d: message" like:
595: Invalid argument
view release on metacpan or search on metacpan
7891011121314151617use
AnyEvent::MP;
$NODE
# contains this node's node ID
NODE
# returns this node's node ID
$SELF
# receiving/own port id in rcv callbacks
# initialise the node so it can send/receive messages
configure;
# ports are message destinations
4243444546474849505152mon
$port
,
$localport
,
@msg
# send message on death
# temporarily execute code in port context
peval
$port
,
sub
{
die
"kill the port!"
};
# execute callbacks in $SELF port context
my
$timer
= AE::timer 1, 0, psub {
die
"kill the port, delayed"
;
};
# distributed database - modification
355356357358359360361362363364365
# or provide a nicer-to-remember nodeid
# aemp run profile seed nodeid "$(hostname)"
=item $SELF
Contains the current port id while executing C<rcv> callbacks or C<psub>
blocks.
=item *SELF, SELF, %SELF, @SELF...
Due to some quirks in how perl exports variables, it is impossible to
393394395396397398399400401402403these.
=item $local_port = port
Create a new local port object and returns its port ID. Initially it has
no callbacks set and will throw an error when it receives messages.
=item $local_port = port { my @msg = @_ }
Creates a new local port, and returns its ID. Semantically the same as
creating a port and calling C<rcv $port, $callback> on it.
446447448449450451452453454455456The
default
callback receives all messages not matched by a more specific
C<tag> match.
=item rcv $local_port, tag => $callback->(@msg_without_tag), ...
Register (or replace) callbacks to be called on messages starting with the
given tag on the given port (and return the port), or unregister it (when
C<$callback> is C<$undef> or missing). There can only be one callback
registered for each tag.
The original message will be passed to the callback, after the first
578579580581582583584585586587588589590591592593=item $closure = psub { BLOCK }
Remembers C<$SELF> and creates a closure out of the BLOCK. When the
closure is executed, sets up the environment in the same way as in C<rcv>
callbacks, i.e. runtime errors will cause the port to get C<kil>ed.
The effect is basically as if it returned C<< sub { peval $SELF, sub {
BLOCK }, @_ } >>.
This is useful when you register callbacks from C<rcv> callbacks:
rcv delayed_reply => sub {
my ($delay, @reply) = @_;
my $timer = AE::timer $delay, 0, psub {
snd @reply, $SELF;
598599600601602603604605606607608sub
psub(&) {
my
$cb
=
shift
;
my
$port
=
$SELF
or Carp::croak
"psub can only be called from within rcv or psub callbacks, not"
;
sub
{
local
$SELF
=
$port
;
if
(
wantarray
) {
753754755756757758759760761762(C<mon
$mport
,
$lport
> form) to get killed.
If a C<
@reason
> is specified, then linked ports (C<mon
$mport
,
$lport
>
form) get killed
with
the same reason.
Runtime errors
while
evaluating C<rcv> callbacks or inside C<psub> blocks
will be reported as reason C<<
die
=> $@ >>.
Transport/communication errors are reported as C<<
transport_error
=>
$message
>>.
view all matches for this distribution
791792793794795796797798799800801C<MyApp::Chat::Server>, C<MyApp::Chat>, C<MyApp>)
until
the function
The init function is then called
with
the newly-created port as context
object (C<
$SELF
>) and the C<
@initdata
>
values
as arguments. It I<must>
call one of the C<rcv> functions to set callbacks on C<
$SELF
>, otherwise
the port might not get created.
A common idiom is to pass a
local
port, immediately monitor the spawned
port, and in the remote init function, immediately monitor the passed
local
port. This two-way monitoring ensures that both ports get cleaned up