… | |
… | |
162 | use common::sense; |
162 | use common::sense; |
163 | |
163 | |
164 | use Coro; |
164 | use Coro; |
165 | use AnyEvent (); |
165 | use AnyEvent (); |
166 | |
166 | |
167 | our $VERSION = 6.03; |
167 | our $VERSION = 6.04; |
168 | |
168 | |
169 | ############################################################################# |
169 | ############################################################################# |
170 | # idle handler |
170 | # idle handler |
171 | |
171 | |
172 | our $IDLE; |
172 | our $IDLE; |
… | |
… | |
234 | # call the readyhook, in case coroutines were already readied |
234 | # call the readyhook, in case coroutines were already readied |
235 | _activity; |
235 | _activity; |
236 | } |
236 | } |
237 | |
237 | |
238 | # augment condvars |
238 | # augment condvars |
239 | |
239 | unshift @AnyEvent::CondVar::ISA, "Coro::AnyEvent::CondVar"; |
240 | *AnyEvent::CondVar::_send = sub { |
|
|
241 | (delete $_[0]{_ae_coro})->ready if $_[0]{_ae_coro}; |
|
|
242 | }; |
|
|
243 | |
|
|
244 | *AnyEvent::CondVar::_wait = sub { |
|
|
245 | do { |
|
|
246 | local $_[0]{_ae_coro} = $Coro::current; |
|
|
247 | Coro::schedule; |
|
|
248 | } until $_[0]{_ae_sent}; |
|
|
249 | }; |
|
|
250 | }; |
240 | }; |
251 | |
241 | |
252 | =item Coro::AnyEvent::poll |
242 | =item Coro::AnyEvent::poll |
253 | |
243 | |
254 | This call will block the current thread until the event loop has polled |
244 | This call will block the current thread until the event loop has polled |
… | |
… | |
355 | my $w = AE::io $_[0], 1, sub { $cb->(1) }; |
345 | my $w = AE::io $_[0], 1, sub { $cb->(1) }; |
356 | my $t = defined $_[1] && AE::timer $_[1], 0, sub { $cb->(0) }; |
346 | my $t = defined $_[1] && AE::timer $_[1], 0, sub { $cb->(0) }; |
357 | Coro::rouse_wait |
347 | Coro::rouse_wait |
358 | } |
348 | } |
359 | |
349 | |
|
|
350 | sub Coro::AnyEvent::CondVar::send { |
|
|
351 | (delete $_[0]{_ae_coro})->ready if $_[0]{_ae_coro}; |
|
|
352 | |
|
|
353 | AnyEvent::CondVar::Base::send $_[0]; |
|
|
354 | }; |
|
|
355 | |
|
|
356 | sub Coro::AnyEvent::CondVar::recv { |
|
|
357 | until ($_[0]{_ae_sent}) { |
|
|
358 | local $_[0]{_ae_coro} = $Coro::current; |
|
|
359 | Coro::schedule; |
|
|
360 | } |
|
|
361 | |
|
|
362 | AnyEvent::CondVar::Base::recv $_[0]; |
|
|
363 | }; |
|
|
364 | |
360 | 1; |
365 | 1; |
361 | |
366 | |
362 | =back |
367 | =back |
363 | |
368 | |
364 | =head1 IMPLEMENTATION DETAILS |
369 | =head1 IMPLEMENTATION DETAILS |