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

Comparing Coro/Coro.pm (file contents):
Revision 1.240 by root, Tue Nov 25 20:48:41 2008 UTC vs.
Revision 1.244 by root, Sat Dec 13 22:08:13 2008 UTC

74 74
75our $idle; # idle handler 75our $idle; # idle handler
76our $main; # main coroutine 76our $main; # main coroutine
77our $current; # current coroutine 77our $current; # current coroutine
78 78
79our $VERSION = 5.11; 79our $VERSION = 5.13;
80 80
81our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub); 81our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub);
82our %EXPORT_TAGS = ( 82our %EXPORT_TAGS = (
83 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)], 83 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)],
84); 84);
352See C<async> and C<Coro::State::new> for additional info about the 352See C<async> and C<Coro::State::new> for additional info about the
353coroutine environment. 353coroutine environment.
354 354
355=cut 355=cut
356 356
357sub _terminate { 357sub _coro_run {
358 terminate &{+shift}; 358 terminate &{+shift};
359} 359}
360 360
361=item $success = $coroutine->ready 361=item $success = $coroutine->ready
362 362
537would cause a deadlock unless there is an idle handler that wakes up some 537would cause a deadlock unless there is an idle handler that wakes up some
538coroutines. 538coroutines.
539 539
540=item my $guard = Coro::guard { ... } 540=item my $guard = Coro::guard { ... }
541 541
542This creates and returns a guard object. Nothing happens until the object 542This function still exists, but is deprecated. Please use the
543gets destroyed, in which case the codeblock given as argument will be 543C<Guard::guard> function instead.
544executed. This is useful to free locks or other resources in case of a
545runtime error or when the coroutine gets canceled, as in both cases the
546guard block will be executed. The guard object supports only one method,
547C<< ->cancel >>, which will keep the codeblock from being executed.
548 544
549Example: set some flag and clear it again when the coroutine gets canceled
550or the function returns:
551
552 sub do_something {
553 my $guard = Coro::guard { $busy = 0 };
554 $busy = 1;
555
556 # do something that requires $busy to be true
557 }
558
559=cut 545=cut
560 546
561sub guard(&) { 547BEGIN { *guard = \&Guard::guard }
562 bless \(my $cb = $_[0]), "Coro::guard"
563}
564
565sub Coro::guard::cancel {
566 ${$_[0]} = sub { };
567}
568
569sub Coro::guard::DESTROY {
570 ${$_[0]}->();
571}
572
573 548
574=item unblock_sub { ... } 549=item unblock_sub { ... }
575 550
576This utility function takes a BLOCK or code reference and "unblocks" it, 551This utility function takes a BLOCK or code reference and "unblocks" it,
577returning a new coderef. Unblocking means that calling the new coderef 552returning a new coderef. Unblocking means that calling the new coderef

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines