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

Comparing Coro/Coro.pm (file contents):
Revision 1.314 by root, Fri Dec 7 23:23:15 2012 UTC vs.
Revision 1.319 by root, Tue Nov 5 14:38:46 2013 UTC

366 366
367our $idle; # idle handler 367our $idle; # idle handler
368our $main; # main coro 368our $main; # main coro
369our $current; # current coro 369our $current; # current coro
370 370
371our $VERSION = 6.23; 371our $VERSION = 6.32;
372 372
373our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub rouse_cb rouse_wait); 373our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub rouse_cb rouse_wait);
374our %EXPORT_TAGS = ( 374our %EXPORT_TAGS = (
375 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)], 375 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)],
376); 376);
1130But from within a coro, you often just want to write this: 1130But from within a coro, you often just want to write this:
1131 1131
1132 my $status = wait_for_child $pid; 1132 my $status = wait_for_child $pid;
1133 1133
1134Coro offers two functions specifically designed to make this easy, 1134Coro offers two functions specifically designed to make this easy,
1135C<Coro::rouse_cb> and C<Coro::rouse_wait>. 1135C<rouse_cb> and C<rouse_wait>.
1136 1136
1137The first function, C<rouse_cb>, generates and returns a callback that, 1137The first function, C<rouse_cb>, generates and returns a callback that,
1138when invoked, will save its arguments and notify the coro that 1138when invoked, will save its arguments and notify the coro that
1139created the callback. 1139created the callback.
1140 1140
1146function mentioned above: 1146function mentioned above:
1147 1147
1148 sub wait_for_child($) { 1148 sub wait_for_child($) {
1149 my ($pid) = @_; 1149 my ($pid) = @_;
1150 1150
1151 my $watcher = AnyEvent->child (pid => $pid, cb => Coro::rouse_cb); 1151 my $watcher = AnyEvent->child (pid => $pid, cb => rouse_cb);
1152 1152
1153 my ($rpid, $rstatus) = Coro::rouse_wait; 1153 my ($rpid, $rstatus) = rouse_wait;
1154 $rstatus 1154 $rstatus
1155 } 1155 }
1156 1156
1157In the case where C<rouse_cb> and C<rouse_wait> are not flexible enough, 1157In the case where C<rouse_cb> and C<rouse_wait> are not flexible enough,
1158you can roll your own, using C<schedule> and C<ready>: 1158you can roll your own, using C<schedule> and C<ready>:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines