ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro.pm
(Generate patch)

Comparing Coro/Coro.pm (file contents):
Revision 1.290 by root, Fri Apr 29 05:29:51 2011 UTC vs.
Revision 1.291 by root, Fri Apr 29 15:43:26 2011 UTC

399our @destroy; 399our @destroy;
400our $manager; 400our $manager;
401 401
402$manager = new Coro sub { 402$manager = new Coro sub {
403 while () { 403 while () {
404 Coro::State::cancel shift @destroy 404 _destroy shift @destroy
405 while @destroy; 405 while @destroy;
406 406
407 &schedule; 407 &schedule;
408 } 408 }
409}; 409};
543coro, regardless of priority. This is useful sometimes to ensure 543coro, regardless of priority. This is useful sometimes to ensure
544progress is made. 544progress is made.
545 545
546=item terminate [arg...] 546=item terminate [arg...]
547 547
548Terminates the current coro with the given status values (see L<cancel>). 548Terminates the current coro with the given status values (see
549L<cancel>). The values will not be copied, but referenced directly.
549 550
550=item Coro::on_enter BLOCK, Coro::on_leave BLOCK 551=item Coro::on_enter BLOCK, Coro::on_leave BLOCK
551 552
552These function install enter and leave winders in the current scope. The 553These function install enter and leave winders in the current scope. The
553enter block will be executed when on_enter is called and whenever the 554enter block will be executed when on_enter is called and whenever the
727Returns true iff this Coro object has been suspended. Suspended Coros will 728Returns true iff this Coro object has been suspended. Suspended Coros will
728not ever be scheduled. 729not ever be scheduled.
729 730
730=item $coro->cancel (arg...) 731=item $coro->cancel (arg...)
731 732
732Terminates the given Coro and makes it return the given arguments as 733Terminates the given Coro object and makes it return the given arguments as
733status (default: an empty list). Never returns if the Coro is the 734status (default: an empty list). Never returns if the Coro is the
734current Coro. 735current Coro.
735 736
736=cut 737The arguments are not copied, but instead will be referenced directly
738(e.g. if you pass C<$var> and after the call change that variable, then
739you might change the return values passed to e.g. C<join>, so don't do
740that).
737 741
738sub cancel { 742The resources of the Coro are usually freed (or destructed) before this
739 my $self = shift; 743call returns, but this can be delayed for an indefinite amount of time, as
740 744in some cases the manager thread has to run first to actually destruct the
741 if ($current == $self) { 745Coro object.
742 terminate @_;
743 } else {
744 $self->{_status} = [@_];
745 Coro::State::cancel $self;
746 }
747}
748 746
749=item $coro->schedule_to 747=item $coro->schedule_to
750 748
751Puts the current coro to sleep (like C<Coro::schedule>), but instead 749Puts the current coro to sleep (like C<Coro::schedule>), but instead
752of continuing with the next coro from the ready queue, always switch to 750of continuing with the next coro from the ready queue, always switch to

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines