--- Coro/Coro.pm 2008/11/24 07:55:28 1.239 +++ Coro/Coro.pm 2008/12/13 19:18:36 1.243 @@ -76,7 +76,7 @@ our $main; # main coroutine our $current; # current coroutine -our $VERSION = 5.1; +our $VERSION = 5.12; our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub); our %EXPORT_TAGS = ( @@ -177,7 +177,7 @@ =item async { ... } [@args...] -Create a new coroutine and return it's coroutine object (usually +Create a new coroutine and return its coroutine object (usually unused). The coroutine will be put into the ready queue, so it will start running automatically on the next scheduler run. @@ -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 { ... } @@ -683,7 +658,7 @@ C and C. The first function, C, generates and returns a callback that, -when invoked, will save it's arguments and notify the coroutine that +when invoked, will save its arguments and notify the coroutine that created the callback. The second function, C, waits for the callback to be called