NAME
Whatbot::IO::Timer - Timer functionality for whatbot.
SYNOPSIS
sub something_awesome : GlobalRegEx('do it later') {
my ( $self, $message ) = @_;
my $medium = $message->origin;
$self->timer->enqueue(10, \&done_later, $self, $medium, "it");
return "ok";
}
sub done_later {
my ( $self, $medium, $what ) = @_;
my $response = Whatbot::Message->new(
from => $medium->me,
to => "",
content => "I did $what"
);
$medium->send_message($response);
}
DESCRIPTION
Whatbot::IO::Timer - Timer functionality for whatbot.
PUBLIC METHODS
- enqueue($when, $sub, [@args ...])
-
The only way to really interact with the timer.
$when
is in seconds -- either seconds since Jan 1 1970 (epoch), or, if less than 86400, seconds from now.$sub
is a reference to any code, and@args
, if provided, are passed directly to that subroutine at call-time. - remove_where_arg( $arg_index, $match )
-
Allow one to remove an item from the queue, based on matching an argument. The queued item must have one or more args, and then the arg at $arg_index must be a reference or number matching $match.
- event_loop()
-
Called every event loop, from the main whatbot class. Runs all code scheduled for this second. If called multiple times per second, only runs once.
LICENSE/COPYRIGHT
Be excellent to each other and party on, dudes.