… | |
… | |
50 | |
50 | |
51 | our $idle; # idle handler |
51 | our $idle; # idle handler |
52 | our $main; # main coroutine |
52 | our $main; # main coroutine |
53 | our $current; # current coroutine |
53 | our $current; # current coroutine |
54 | |
54 | |
55 | our $VERSION = '3.3'; |
55 | our $VERSION = '3.55'; |
56 | |
56 | |
57 | our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub); |
57 | our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub); |
58 | our %EXPORT_TAGS = ( |
58 | our %EXPORT_TAGS = ( |
59 | prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)], |
59 | prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)], |
60 | ); |
60 | ); |
… | |
… | |
233 | our $POOL_SIZE = 8; |
233 | our $POOL_SIZE = 8; |
234 | our @pool; |
234 | our @pool; |
235 | |
235 | |
236 | sub pool_handler { |
236 | sub pool_handler { |
237 | while () { |
237 | while () { |
238 | my ($cb, @arg) = @{ delete $current->{_invoke} }; |
|
|
239 | |
|
|
240 | eval { |
238 | eval { |
|
|
239 | my ($cb, @arg) = @{ delete $current->{_invoke} or return }; |
241 | $cb->(@arg); |
240 | $cb->(@arg); |
242 | }; |
241 | }; |
243 | warn $@ if $@; |
242 | warn $@ if $@; |
244 | |
243 | |
245 | last if @pool >= $POOL_SIZE; |
244 | last if @pool >= $POOL_SIZE; |
246 | push @pool, $current; |
245 | push @pool, $current; |
247 | |
246 | |
|
|
247 | $current->save (Coro::State::SAVE_DEF); |
248 | $current->prio (0); |
248 | $current->prio (0); |
249 | schedule; |
249 | schedule; |
250 | } |
250 | } |
251 | } |
251 | } |
252 | |
252 | |
… | |
… | |
466 | and C<schedule> would cause a deadlock unless there is an idle handler |
466 | and C<schedule> would cause a deadlock unless there is an idle handler |
467 | that wakes up some coroutines. |
467 | that wakes up some coroutines. |
468 | |
468 | |
469 | =item my $guard = Coro::guard { ... } |
469 | =item my $guard = Coro::guard { ... } |
470 | |
470 | |
471 | This creates and returns a guard object. Nothing happens until the objetc |
471 | This creates and returns a guard object. Nothing happens until the object |
472 | gets destroyed, in which case the codeblock given as argument will be |
472 | gets destroyed, in which case the codeblock given as argument will be |
473 | executed. This is useful to free locks or other resources in case of a |
473 | executed. This is useful to free locks or other resources in case of a |
474 | runtime error or when the coroutine gets canceled, as in both cases the |
474 | runtime error or when the coroutine gets canceled, as in both cases the |
475 | guard block will be executed. The guard object supports only one method, |
475 | guard block will be executed. The guard object supports only one method, |
476 | C<< ->cancel >>, which will keep the codeblock from being executed. |
476 | C<< ->cancel >>, which will keep the codeblock from being executed. |