Coro::Event - do events the coro-way |
Coro::Event - do events the coro-way
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;
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 the Event manpage). 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.
flavour(args...)
Examples:
my $reader = Coro::Event->io(fd => $filehandle, poll => 'r'); $reader->next;
do_flavour(args...)
The reason this function exists is that you sometimes want to serve events
while doing other work. Calling Coro::cede
does not work because
cede
implies that the current coroutine is runnable and does not call
into the Event dispatcher.
loop([$timeout])
loop
you should use instead of Event::loop
when using this module - it will ensure correct scheduling in the presence
of events.
unloop([$result])
Marc Lehmann <pcg@goof.com> http://www.goof.com/pcg/marc/
Coro::Event - do events the coro-way |