UV::Check - Check handles in libuv
#!/usr/bin/env perl use strict; use warnings; use UV; # A new handle will be initialized against the default loop my $check = UV::Check->new(); # Use a different loop my $loop = UV::Loop->new(); # non-default loop my $check = UV::Check->new($loop); # setup the check callback: $check->on(check => sub {say "We're CHECKING!!!"}); # start the check $check->start(); # or, with an explicit callback defined $check->start(sub {say "override any 'check' callback we already have"}); # stop the check $check->stop();
This module provides an interface to libuv's check handle.
Check handles will run the given callback once per loop iteration, right after polling for i/o.
UV::Check inherits all events from UV::Handle and also makes the following extra events available.
$handle->on(check => sub { my $invocant = shift; say "We are checking!"}); my $count = 0; $handle->on("check", sub { my $invocant = shift; # the check instance this event fired on if (++$count > 2) { say "We've checked twice. stopping!"; $invocant->stop(); } });
When the event loop runs and the check is ready, this event will be fired.
UV::Check inherits all methods from UV::Handle and also makes the following extra methods available.
my $check = UV::Check->new(); # Or tell it what loop to initialize against my $check = UV::Check->new($loop);
This constructor method creates a new UV::Check object and initializes the check with the given UV::Loop. If no UV::Loop is provided, then the "default_loop" in UV::Loop is assumed.
# start the handle with a callback we supplied with ->on() or with no cb $check->start(); # pass a callback for the "check" event $check->start(sub {say "yay"}); # providing the callback above completely overrides any callback previously # set in the ->on() method. It's equivalent to: $check->on(check => sub {say "yay"}); $check->start();
The start method starts the check handle.
$check->stop();
The stop method stops the check handle. The callback will no longer be called.
Chase Whitener <capoeirab@cpan.org>
Daisuke Murase <typester@cpan.org>
Copyright 2012, Daisuke Murase.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install UV, copy and paste the appropriate command in to your terminal.
cpanm
cpanm UV
CPAN shell
perl -MCPAN -e shell install UV
For more information on module installation, please visit the detailed CPAN module installation guide.