NAME

UV::Check - Check handles in libuv

SYNOPSIS

#!/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 => $loop,
  on_close => sub {say "close!"},
  on_check => sub {say "check!"},
);

# 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();

DESCRIPTION

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.

EVENTS

UV::Check inherits all events from UV::Handle and also makes the following extra events available.

check

$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.

METHODS

UV::Check inherits all methods from UV::Handle and also makes the following extra methods available.

new

my $check = UV::Check->new();
# Or tell it what loop to initialize against
my $check = UV::Check->new(
    loop => $loop,
    on_close => sub {say "close!"},
    on_check => sub {say "check!"},
);

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

# 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.

Returns the $check instance itself.

stop

$check->stop();

The stop method stops the check handle. The callback will no longer be called.

AUTHOR

Chase Whitener <capoeirab@cpan.org>

AUTHOR EMERITUS

Daisuke Murase <typester@cpan.org>

COPYRIGHT AND LICENSE

Copyright 2012, Daisuke Murase.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.