Event::timer#

📦 max

A timer watcher: an event at a given time, and optionally at every interval after it. Times are in the units of Event::time - seconds, fractional when Time::HiRes is loaded, which use Event does.

Event->timer(%attributes) (or Event::timer->new(...)) takes the shared attributes of Event::Watcher, the ones below, and after:

  • at => $time - the first expiry.

  • after => $seconds - the first expiry, that many seconds from now; also the interval when none is given. at and after together die “‘after’ and ‘at’ are mutually exclusive”.

  • interval => $seconds - repeat this often. Given alone, the first expiry is one interval from now.

A timer repeats when it was given interval (or after, which sets it), unless repeat => 0 is given; otherwise it fires once. Its default priority is PRIO_NORMAL.

Synopsis#

use Event;

Event->timer(after => 0.5, cb => sub { print "once\n" }, repeat => 0);
Event->timer(interval => 1, cb => sub { print "every second\n" });
Event::loop();

Functions#

Attributes#

at#

The time of the next expiry. Setting it moves an active timer to the new time.

hard#

How a repeating timer reckons its next expiry: when true, one interval after the expiry just handled, so the timer keeps to its schedule however long the callback takes; when false (the default), one interval after the callback returned.

interval#

Seconds between expiries: a number, or a reference to a number, which is then read at every expiry. A negative interval warns and counts as 0; anything else that is not a number dies.