NAME
Event - Event loop processing
WARNING
THIS IS EXPERIMENTAL CODE AND IS LIKELY TO CHANGE A CONSIDERABLE AMOUNT BEFORE IT IS RELEASED FOR GENERAL USE.
SYNOPSIS
use Event;
# initialize application
my $ret = Event::Loop::Loop();
# and some callback will call
Event::Loop::exitLoop('ok');
DESCRIPTION
EVENTS
The following properties are common to all events.
- queuing
-
An event can only be queued once.
- cancel
- priority
-
A default priority is assigned to each event upon creation. The default depends on the type of the event. A +- offset from the default can be passed via the
prioritykey. If thepriorityis a negative number the callback will be called immediately, otherwise it will be pushed onto the event queue. While it may seem advantageous to use a negative priorities, it defeats the purpose of even having an event queue in the first place. - now
-
Events can be queued manually with the
nowmethod. Anynowadditional arguments passed to now are forwarded to the event callback. You must provide whatever arguments your event handler is expecting since thenowmethod bypasses the usual dispatch apparatus.
EVENT TYPES
- idle
-
Event->idle(callback => \&idle);Call
&idlewhen the loop is idle. - watchvar
-
$e = Event->watchvar( variable => \$var, callback => \&watcher, );Call
&watcherwhen$varis changed.When called
&watcherwill be passed$eas the first argument. - timer
-
$e = Event->timer( after => 10, at => time + 10, interval => 2, callback => \&timeout );Call
&timeouteither after a given delay or at a given time (afterandatare mutually exclusive). Then optionally call&timeoutat given intervals.When called
&timeoutwill be passed$eas the first argument, and the time that the event was triggered as the second argument. Ifintervalwas not given andafterwas then&timeoutmay call theagainmethod on$ewhich will cause the event to re-occur, the time at which the event will re-occur is the value given byafteradded to the time the event was triggered.Due to lags in the event loop, the re-queued timeout may already be in the past. If the 'hard' flags was set, the event will be queued for execution immediately. Otherwise, the new timeout will be calculated relative to the current time (this is the default).
- io
-
$e = Event->io( handle => $sock, events => 'r', callback => \&ready );Call
&readywhen$sockhas data to be read.eventtakes one or more of 'r', 'w', or 'e'. These correspond to read, write, and exceptional data, respectively.When called
&readyis passed$eas the first argument,$handleas the second argument and the events that happened as the third argument.&readymay call thecancelmethod on$eto stop any future event handling on$handle - signal
-
$e = Event->signal( signal => 'INT', callback => \&interrupt );Call
&interruptwhen anINTsignal is received.signalaccepts any signal name exceptCHLD, see below.When called
&interruptwill be passed$eas the first argument and the name of the signal as the second.&interruptamy call thecancelmethod on$eto stop any future events being caught. - process
-
$e = Event->process( pid => $pid, callback => \&reap );Call
&reapwhen the child process with pid$pidexits. If$pidis not given then&reapwill be called for any process that does not have it's own event handler.When called
&reapwill be passed$eas the first parameter, the process id of the child as the second and the exit status of the child as the third.&reapmay call thecancelmethod on$eto stop future process events but this is only of use on event handlers wherepidis not specified.
CALLBACK ARGUMENTS
The arguments passed to the event callback depends on the type of the event handler:
io $event
process $event, $pid, $status
signal $event, $name, $count
timer $event, $when
watchvar $event, $ref
Event::Loop API
- $Now
-
Time::HiRes::time() cache for low-accuracy clients.
- queueEvent
- doOneEvent
- Loop
- exitLoop
- PRIO_HIGH, PRIO_NORMAL, QUEUES
A COMMENT ON THE DESIGN
While object-oriented design has gained popularity in recent times, Event does not follow these ideas as strictly as it might. Performance cannot be sacrificed for theoretical beauty. Real beauty is to balance the solution to the requirements, without elaboration.
DIRECTION
# generate an event when we can successfully run an op
$e = Event->semaphore(
semaphore => $sem,
op => $op,
callback => \&gotit
);
# generate an event when the msg queue is/is not empty
$e = Event->msg(
msg => $msg,
callback => \&doit
);
AUTHORS
Graham Barr <gbarr@pobox.com>, Joshua Pritikin <bitset@mindspring.com>
COPYRIGHT
Copyright © 1997-1998 Graham Barr. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 214:
Non-ASCII character seen before =encoding in '©'. Assuming CP1252