NAME
Coro::Event - do events the coro-way
SYNOPSIS
use Coro;
use Coro::Event;
sub keyboard : Coro {
my $w = Coro::Event->io(fd => *STDIN, poll => 'r');
while() {
print "cmd> ";
my $ev = $w->next; my $cmd = <STDIN>;
unloop unless $cmd ne "";
print "data> ";
my $ev = $w->next; my $data = <STDIN>;
}
}
&loop;
DESCRIPTION
This module enables you to create programs using the powerful Event model (and module), while retaining the linear style known from simple or threaded programs.
This module provides a method and a function for every watcher type (flavour) (see Event). The only difference between these and the watcher constructors from Event is that you do not specify a callback function - it will be managed by this module.
Your application should just create all necessary coroutines and then call Coro::Event->main.
- $w = Coro::Event->flavour(args...)
-
Create and return a watcher of the given type.
Examples:
my $reader = Coro::Event->io(fd => $filehandle, poll => 'r'); $reader->next;
- $w->next
-
Return the next event of the event queue of the watcher.
- do_flavour(args...)
-
Create a watcher of the given type and immediately call it's next method. This is less efficient then calling the constructor once and the next method often, but it does save typing sometimes.
- sweep
-
Similar to Event::one_event and Event::sweep: The idle task is called once (this has the effect of jumping back into the Event loop once to serve new events).
The reason this function exists is that you sometimes want to serve events while doing other work. Calling
Coro::cede
does not work becausecede
implies that the current coroutine is runnable and does not call into the Event dispatcher. - $result = loop([$timeout])
-
This is the version of
loop
you should use instead ofEvent::loop
when using this module - it will ensure correct scheduling in the presence of events. - unloop([$result])
-
Same as Event::unloop (provided here for your convinience only).
AUTHOR
Marc Lehmann <pcg@goof.com>
http://www.goof.com/pcg/marc/
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 190:
You forgot a '=back' before '=head1'