Event::generic::Source#

📦 max

An event source for generic watchers (see Event::generic): calling its event method gives an event to each of its active watchers.

Written in Perl (Event/generic.pm), beside the methods below:

  • Event::generic::Source->new - a new source.

  • $source->watch(%attributes) - a new Event::generic watcher of this source, as Event->generic(source => $source, %attributes).

A source lives as long as a reference to it does, and each of its watchers holds one, so it normally outlives them.

Differences from upstream#

  • A source destroyed while watchers still watch it - by calling its DESTROY directly - stops those watchers, as if their source were set to undef. Afterwards event on it queues nothing, its watchers cannot be started (“without source”), and perl’s own later DESTROY of it is harmless. XS Event frees the source but leaves its watchers linked to the freed memory, and frees it a second time; perl aborts with “double free or corruption” (t/81-xs-native/Event/350-source-destroyed.t).

Synopsis#

use Event;
use Event::generic;

my $jobs = Event::generic::Source->new;
$jobs->watch(cb => sub { run_job($_[0]->data) });
$jobs->event({ id => 1 });
Event::loop();

Functions#

Sources#

allocate#

The constructor’s primitive: a new source blessed into $class, with $template (a hash or array reference) as the object; new calls it with an empty hash. Dies “Bad template” when $template is no reference.

event#

$source->event or $source->event($data): queue one event on every active watcher of the source. A copy of $data (undef when omitted) becomes each event’s data. Returns nothing.