… | |
… | |
138 | |
138 | |
139 | shift eq Coro::Event:: |
139 | shift eq Coro::Event:: |
140 | or croak "event constructor \"Coro::Event->$flavour\" must be called as a static method"; |
140 | or croak "event constructor \"Coro::Event->$flavour\" must be called as a static method"; |
141 | |
141 | |
142 | my $w = $new->($class, |
142 | my $w = $new->($class, |
143 | desc => $flavour, |
143 | desc => $flavour, |
144 | @_, |
144 | @_, |
145 | parked => 1, |
145 | parked => 1, |
146 | ); |
146 | ); |
147 | |
147 | |
148 | _install_std_cb $w, $type; |
148 | _install_std_cb $w, $type; |
149 | |
149 | |
150 | # reblessing due to Event being broken |
150 | # reblessing due to Event being broken |
151 | bless $w, $class |
151 | bless $w, $class |
152 | }; |
152 | }; |
153 | *{ $flavour } = $coronew; |
153 | *{ $flavour } = $coronew; |
154 | *{"do_$flavour"} = sub { |
154 | *{"do_$flavour"} = sub { |
155 | unshift @_, Coro::Event::; |
155 | unshift @_, Coro::Event::; |
156 | @_ = &$coronew; |
156 | next_cancel (&$coronew); |
157 | &Coro::schedule while &_next; |
|
|
158 | $_[0]->cancel; |
|
|
159 | &_event |
|
|
160 | }; |
157 | }; |
161 | } |
|
|
162 | |
|
|
163 | # do schedule in perl to avoid forcing a stack allocation. |
|
|
164 | # this is about 10% slower, though. |
|
|
165 | sub next($) { |
|
|
166 | &Coro::schedule while &_next; |
|
|
167 | |
|
|
168 | &_event |
|
|
169 | } |
158 | } |
170 | |
159 | |
171 | sub Coro::Event::Event::hits { $_[0][3] } |
160 | sub Coro::Event::Event::hits { $_[0][3] } |
172 | sub Coro::Event::Event::got { $_[0][4] } |
161 | sub Coro::Event::Event::got { $_[0][4] } |
173 | |
162 | |