NAME
Async::Selector::Watcher - representation of resource watch in Async::Selector
VERSION
1.03
SYNOPSIS
use Async::Selector;
my $s = Async::Selector->new();
setup_resources_with($s);
## Obtain a watcher from Selector.
my $watcher = $s->watch(a => 1, b => 2, sub {
my ($w, %res) = @_;
handle_a($res{a}) if exists $res{a};
handle_b($res{b}) if exists $res{b};
});
## Is the watcher active?
$watcher->active; ## => true
## Get the list of watched resources
my @resources = sort $watcher->resources; ## => ('a', 'b')
## Get the watcher conditions
my %conditions = $watcher->conditions; ## => (a => 1, b => 2)
## Cancel the watcher
$watcher->cancel;
DESCRIPTION
Async::Selector::Watcher is an object that stores information about a resource watch in Async::Selector module. It also provides its user with a way to cancel the watch.
CLASS METHODS
Nothing.
Async::Selector::Watcher objects are created by watch()
, watch_lt()
and watch_et()
methods of Async::Selector.
OBJECT METHODS
In the following description, $watcher
is an Async::Selector::Watcher object.
$is_active = $watcher->active();
Returns true if the Async::Selector::Watcher is active. Returns false otherwise.
Active watchers are the ones in Async::Selector objects, watching some of the Selector's resources. Callback functions of active watchers can be executed if the watched resources get available.
Inactive watchers are the ones that have been removed from Async::Selector objects. Their callback functions are never executed any more.
Note that watchers are automatically canceled and become inactive when their parent Async::Selector object is destroyed.
$watcher->cancel();
Cancels the watch.
The $watcher
then becomes inactive and is removed from the Async::Selector object it used to belong to.
@resources = $watcher->resources();
Returns the list of resource names that are watched by this Async::Selector::Watcher object.
%conditions = $watcher->conditions();
Returns a hash whose keys are the resource names that are watched by this Async::Selector::Watcher object, and values are the condition inputs for the resources.
SEE ALSO
AUTHOR
Toshio Ito, <toshioito at cpan.org>
LICENSE AND COPYRIGHT
Copyright 2012-2013 Toshio Ito.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.