… | |
… | |
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 | |
30 | This module enables you to create programs using the powerful Event model |
33 | This 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 |
32 | threaded programs. |
35 | threaded programs. |
… | |
… | |
46 | |
49 | |
47 | =head1 WARNING |
50 | =head1 WARNING |
48 | |
51 | |
49 | Please note that Event does not support coroutines or threads. That |
52 | Please note that Event does not support coroutines or threads. That |
50 | means that you B<MUST NOT> block in an event callback. Again: In Event |
53 | means that you B<MUST NOT> block in an event callback. Again: In Event |
51 | callbacks, you I<must never ever> call a Coroutine fucntion that blocks |
54 | callbacks, you I<must never ever> call a Coroutine function that blocks |
52 | the current coroutine. |
55 | the current coroutine. |
53 | |
56 | |
54 | While this seems to work superficially, it will eventually cause memory |
57 | While this seems to work superficially, it will eventually cause memory |
55 | corruption. |
58 | corruption and often results in deadlocks. |
|
|
59 | |
|
|
60 | Best practise is to always use B<Coro::unblock_sub> for your callbacks. |
56 | |
61 | |
57 | =head1 SEMANTICS |
62 | =head1 SEMANTICS |
58 | |
63 | |
59 | Whenever Event blocks (e.g. in a call to C<one_event>, C<loop> etc.), |
64 | Whenever Event blocks (e.g. in a call to C<one_event>, C<loop> etc.), |
60 | this module cede's to all other coroutines with the same or higher |
65 | this module cede's to all other coroutines with the same or higher |
… | |
… | |
197 | |
202 | |
198 | Same as Event::unloop (provided here for your convinience only). |
203 | Same 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 |
|
|
208 | our $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 | |
204 | 1; |
217 | 1; |
205 | |
218 | |
206 | =back |
219 | =back |
207 | |
220 | |