--- cvsroot/Coro/Coro.pm 2007/09/22 22:39:15 1.135 +++ cvsroot/Coro/Coro.pm 2007/10/02 10:38:17 1.141 @@ -52,7 +52,7 @@ our $main; # main coroutine our $current; # current coroutine -our $VERSION = '3.7'; +our $VERSION = '3.8'; our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub); our %EXPORT_TAGS = ( @@ -243,16 +243,14 @@ while () { eval { while () { -# &{&_pool_1 or &terminate}; # crashes, would be ~5% faster - $cb = &_pool_1 - or &terminate; + _pool_1 $cb; &$cb; - undef $cb; - &terminate if &_pool_2; + _pool_2 $cb; &schedule; } }; + last if $@ eq "\3terminate\2\n"; warn $@ if $@; } } @@ -312,12 +310,25 @@ Terminates the current coroutine with the given status values (see L). +=item killall + +Kills/terminates/cancels all coroutines except the currently running +one. This is useful after a fork, either in the child or the parent, as +usually only one of them should inherit the running coroutines. + =cut sub terminate { $current->cancel (@_); } +sub killall { + for (Coro::State::list) { + $_->cancel + if $_ != $current && UNIVERSAL::isa $_, "Coro"; + } +} + =back # dynamic methods