EV::Periodic#

📦 max

A wall-clock timer, as EV::periodic makes: its callback runs at a given time, at every multiple of an interval, or whenever a reschedule sub says - see EV::periodic for the three modes. These methods read and change its schedule; the methods all watchers share are EV::Watcher’s.

Changing the offset or interval takes effect at the next firing; set, again and a new reschedule sub take effect at once.

Synopsis#

my $w = EV::periodic 0, 3600, 0, sub { print "on the hour\n" };
printf "next at %s\n", scalar localtime $w->at;
$w->interval(1800);    # on the half hour, from the next firing

Differences from upstream#

  • reschedule_cb returns the sub without letting it go: upstream frees the watcher’s sub when the returned copy goes away, so every later firing fails with EV: error in callback (ignoring): Not a CODE reference, and setting one frees the old sub twice (Attempt to free unreferenced scalar).

  • A reschedule sub set with reschedule_cb on a watcher made without one is used; upstream never calls it, and clearing one makes every later firing fail.

  • The watcher and the time a reschedule sub is called with are freed after the call; upstream leaks both, and the watcher with them.

Covered by t/81-xs-native/EV/300-periodic-reschedule-cb.t.

Functions#

Schedule#

again#

Stop the watcher and start it again, computing its next firing time anew - after the clock or the reschedule sub’s idea of time changed.

set#

Set the whole schedule anew: $w->set($at, $interval, $reschedule_cb), the interval and sub optional, as EV::periodic takes them. A negative interval croaks interval value must be >= 0.

at#

When the watcher fires next, in seconds since the epoch.

offset#

The $at the schedule counts from - the offset of the interval’s multiples; with an argument, set a new one (from the next firing) and return the old.

interval#

The interval, 0 for none; with an argument, set a new one (from the next firing) and return the old. A negative one croaks interval value must be >= 0.

reschedule_cb#

The reschedule sub, undef for none; with an argument, use that sub (or none, given a false value) from now on and return the old one. The sub is called with the watcher and the current time and returns the next time to fire; it must not stop or change any periodic watcher or call into the loop. Unlike upstream, the sub returned stays the watcher’s, and one set later is used (see Differences from upstream above; covered by t/81-xs-native/EV/300-periodic-reschedule-cb.t).