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>;


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.

$w = Coro::Event->flavour(args...)
Create and return a watcher of the given type.


  my $reader = Coro::Event->io(fd => $filehandle, poll => 'r');

Return the next event of the event queue of the watcher.

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.

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 because cede 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 of Event::loop when using this module - it will ensure correct scheduling in the presence of events.

Same as Event::unloop (provided here for your convinience only).


 Marc Lehmann <>

 Coro::Event - do events the coro-way