… | |
… | |
18 | } |
18 | } |
19 | } |
19 | } |
20 | |
20 | |
21 | loop; |
21 | loop; |
22 | |
22 | |
|
|
23 | # wait for input on stdin for one second |
|
|
24 | |
|
|
25 | Coro::Event::do_io (fd => \*STDIN, timeout => 1) & Event::Watcher::R |
|
|
26 | or die "no input received"; |
|
|
27 | |
23 | =head1 DESCRIPTION |
28 | =head1 DESCRIPTION |
24 | |
29 | |
25 | This module enables you to create programs using the powerful Event model |
30 | This module enables you to create programs using the powerful Event model |
26 | (and module), while retaining the linear style known from simple or |
31 | (and module), while retaining the linear style known from simple or |
27 | threaded programs. |
32 | threaded programs. |
… | |
… | |
102 | |
107 | |
103 | =cut |
108 | =cut |
104 | |
109 | |
105 | =item $w->next |
110 | =item $w->next |
106 | |
111 | |
107 | Return the next event of the event queue of the watcher. |
112 | Wait for and return the next event of the event queue of the watcher. The |
|
|
113 | returned event objects support two methods only: C<hits> and C<got>, both |
|
|
114 | of which return integers: the number this watcher was hit for this event, |
|
|
115 | and the mask of poll events received. |
108 | |
116 | |
109 | =cut |
117 | =cut |
110 | |
118 | |
111 | =item do_flavour args... |
119 | =item do_flavour args... |
112 | |
120 | |
113 | Create a watcher of the given type and immediately call it's next |
121 | Create a watcher of the given type and immediately call it's next method, |
|
|
122 | returning the event. |
|
|
123 | |
114 | method. This is less efficient then calling the constructor once and the |
124 | This is less efficient then calling the constructor once and the next |
115 | next method often, but it does save typing sometimes. |
125 | method often, but it does save typing sometimes. |
116 | |
126 | |
117 | =cut |
127 | =cut |
118 | |
128 | |
119 | for my $flavour (qw(idle var timer io signal)) { |
129 | for my $flavour (qw(idle var timer io signal)) { |
120 | push @EXPORT, "do_$flavour"; |
130 | push @EXPORT, "do_$flavour"; |
… | |
… | |
156 | &Coro::schedule while &_next; |
166 | &Coro::schedule while &_next; |
157 | |
167 | |
158 | &_event |
168 | &_event |
159 | } |
169 | } |
160 | |
170 | |
|
|
171 | sub Coro::Event::Event::hits { $_[0][3] } |
161 | sub Coro::Event::w { $_[0] } |
172 | sub Coro::Event::Event::got { $_[0][4] } |
162 | sub Coro::Event::prio { $_[0]{Coro::Event}[3] } |
|
|
163 | sub Coro::Event::hits { $_[0]{Coro::Event}[4] } |
|
|
164 | sub Coro::Event::got { $_[0]{Coro::Event}[5] } |
|
|
165 | |
173 | |
166 | =item sweep |
174 | =item sweep |
167 | |
175 | |
168 | Similar to Event::one_event and Event::sweep: The idle task is called once |
176 | Similar to Event::one_event and Event::sweep: The idle task is called once |
169 | (this has the effect of jumping back into the Event loop once to serve new |
177 | (this has the effect of jumping back into the Event loop once to serve new |