ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Event/Event.pm
(Generate patch)

Comparing Coro/Event/Event.pm (file contents):
Revision 1.51 by root, Wed Oct 10 03:33:47 2007 UTC vs.
Revision 1.52 by root, Fri Oct 19 05:52:41 2007 UTC

23 # wait for input on stdin for one second 23 # wait for input on stdin for one second
24 24
25 Coro::Event::do_io (fd => \*STDIN, timeout => 1) & Event::Watcher::R 25 Coro::Event::do_io (fd => \*STDIN, timeout => 1) & Event::Watcher::R
26 or die "no input received"; 26 or die "no input received";
27 27
28 # use a separate coroutine for event processing, if impossible in main:
29 Coro::async { Event::loop };
30
28=head1 DESCRIPTION 31=head1 DESCRIPTION
29 32
30This module enables you to create programs using the powerful Event model 33This module enables you to create programs using the powerful Event model
31(and module), while retaining the linear style known from simple or 34(and module), while retaining the linear style known from simple or
32threaded programs. 35threaded programs.
46 49
47=head1 WARNING 50=head1 WARNING
48 51
49Please note that Event does not support coroutines or threads. That 52Please note that Event does not support coroutines or threads. That
50means that you B<MUST NOT> block in an event callback. Again: In Event 53means that you B<MUST NOT> block in an event callback. Again: In Event
51callbacks, you I<must never ever> call a Coroutine fucntion that blocks 54callbacks, you I<must never ever> call a Coroutine function that blocks
52the current coroutine. 55the current coroutine.
53 56
54While this seems to work superficially, it will eventually cause memory 57While this seems to work superficially, it will eventually cause memory
55corruption. 58corruption and often results in deadlocks.
59
60Best practise is to always use B<Coro::unblock_sub> for your callbacks.
56 61
57=head1 SEMANTICS 62=head1 SEMANTICS
58 63
59Whenever Event blocks (e.g. in a call to C<one_event>, C<loop> etc.), 64Whenever Event blocks (e.g. in a call to C<one_event>, C<loop> etc.),
60this module cede's to all other coroutines with the same or higher 65this module cede's to all other coroutines with the same or higher
197 202
198Same as Event::unloop (provided here for your convinience only). 203Same as Event::unloop (provided here for your convinience only).
199 204
200=cut 205=cut
201 206
202$Coro::idle = \&Event::one_event; # inefficient 207# very inefficient
208our $event_idle = new Coro sub {
209 while () {
210 &Event::one_event;
211 &Coro::schedule;
212 }
213};
214
215$Coro::idle = sub { $event_idle->ready };
203 216
2041; 2171;
205 218
206=back 219=back
207 220

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines