--- cvsroot/Coro/Coro.pm 2006/12/04 21:56:00 1.98 +++ cvsroot/Coro/Coro.pm 2006/12/29 08:36:34 1.101 @@ -52,7 +52,7 @@ our $main; # main coroutine our $current; # current coroutine -our $VERSION = '3.1'; +our $VERSION = '3.3'; our @EXPORT = qw(async cede schedule terminate current unblock_sub); our %EXPORT_TAGS = ( @@ -155,8 +155,11 @@ # remove itself from the runqueue while (@destroy) { my $coro = pop @destroy; + $coro->{status} ||= []; - $_->ready for @{delete $coro->{join} || []}; + + $_->ready for @{(delete $coro->{join} ) || []}; + $_->(@{$coro->{status}}) for @{(delete $coro->{destroy_cb}) || []}; # the next line destroys the coro state, but keeps the # coroutine itself intact (we basically make it a zombie @@ -317,6 +320,20 @@ wantarray ? @{$self->{status}} : $self->{status}[0]; } +=item $coroutine->on_destroy (\&cb) + +Registers a callback that is called when this coroutine gets destroyed, +but before it is joined. The callback gets passed the terminate arguments, +if any. + +=cut + +sub on_destroy { + my ($self, $cb) = @_; + + push @{ $self->{destroy_cb} }, $cb; +} + =item $oldprio = $coroutine->prio ($newprio) Sets (or gets, if the argument is missing) the priority of the