--- Coro/Coro.pm 2008/11/25 20:48:41 1.240 +++ Coro/Coro.pm 2008/12/13 22:08:13 1.244 @@ -76,7 +76,7 @@ our $main; # main coroutine our $current; # current coroutine -our $VERSION = 5.11; +our $VERSION = 5.13; our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub); our %EXPORT_TAGS = ( @@ -354,7 +354,7 @@ =cut -sub _terminate { +sub _coro_run { terminate &{+shift}; } @@ -539,37 +539,12 @@ =item my $guard = Coro::guard { ... } -This creates and returns a guard object. Nothing happens until the object -gets destroyed, in which case the codeblock given as argument will be -executed. This is useful to free locks or other resources in case of a -runtime error or when the coroutine gets canceled, as in both cases the -guard block will be executed. The guard object supports only one method, -C<< ->cancel >>, which will keep the codeblock from being executed. - -Example: set some flag and clear it again when the coroutine gets canceled -or the function returns: - - sub do_something { - my $guard = Coro::guard { $busy = 0 }; - $busy = 1; - - # do something that requires $busy to be true - } +This function still exists, but is deprecated. Please use the +C function instead. =cut -sub guard(&) { - bless \(my $cb = $_[0]), "Coro::guard" -} - -sub Coro::guard::cancel { - ${$_[0]} = sub { }; -} - -sub Coro::guard::DESTROY { - ${$_[0]}->(); -} - +BEGIN { *guard = \&Guard::guard } =item unblock_sub { ... }