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

Comparing Coro/Coro.pm (file contents):
Revision 1.145 by root, Wed Oct 3 16:03:17 2007 UTC vs.
Revision 1.151 by root, Sat Oct 6 19:25:00 2007 UTC

50 50
51our $idle; # idle handler 51our $idle; # idle handler
52our $main; # main coroutine 52our $main; # main coroutine
53our $current; # current coroutine 53our $current; # current coroutine
54 54
55our $VERSION = '4.0'; 55our $VERSION = '4.03';
56 56
57our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub); 57our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub);
58our %EXPORT_TAGS = ( 58our %EXPORT_TAGS = (
59 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)], 59 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)],
60); 60);
219issued in case of an exception instead of terminating the program, as 219issued in case of an exception instead of terminating the program, as
220C<async> does. As the coroutine is being reused, stuff like C<on_destroy> 220C<async> does. As the coroutine is being reused, stuff like C<on_destroy>
221will not work in the expected way, unless you call terminate or cancel, 221will not work in the expected way, unless you call terminate or cancel,
222which somehow defeats the purpose of pooling. 222which somehow defeats the purpose of pooling.
223 223
224The priority will be reset to C<0> after each job, otherwise the coroutine 224The priority will be reset to C<0> after each job, tracing will be
225will be re-used "as-is". 225disabled, the description will be reset and the default output filehandle
226gets restored, so you can change alkl these. Otherwise the coroutine will
227be re-used "as-is": most notably if you change other per-coroutine global
228stuff such as C<$/> you need to revert that change, which is most simply
229done by using local as in C< local $/ >.
226 230
227The pool size is limited to 8 idle coroutines (this can be adjusted by 231The pool size is limited to 8 idle coroutines (this can be adjusted by
228changing $Coro::POOL_SIZE), and there can be as many non-idle coros as 232changing $Coro::POOL_SIZE), and there can be as many non-idle coros as
229required. 233required.
230 234
251 _pool_2 $cb; 255 _pool_2 $cb;
252 &schedule; 256 &schedule;
253 } 257 }
254 }; 258 };
255 259
256 last if $@ eq "\3terminate\2\n"; 260 last if $@ eq "\3async_pool terminate\2\n";
257 warn $@ if $@; 261 warn $@ if $@;
258 } 262 }
259} 263}
260 264
261sub async_pool(&@) { 265sub async_pool(&@) {
466Sets (or gets in case the argument is missing) the description for this 470Sets (or gets in case the argument is missing) the description for this
467coroutine. This is just a free-form string you can associate with a coroutine. 471coroutine. This is just a free-form string you can associate with a coroutine.
468 472
469This method simply sets the C<< $coroutine->{desc} >> member to the given string. You 473This method simply sets the C<< $coroutine->{desc} >> member to the given string. You
470can modify this member directly if you wish. 474can modify this member directly if you wish.
475
476=item $coroutine->throw ([$scalar])
477
478If C<$throw> is specified and defined, it will be thrown as an exception
479inside the coroutine at the next convinient point in time (usually after
480it gains control at the next schedule/transfer/cede). Otherwise clears the
481exception object.
482
483The exception object will be thrown "as is" with the specified scalar in
484C<$@>, i.e. if it is a string, no line number or newline will be appended
485(unlike with C<die>).
486
487This can be used as a softer means than C<cancel> to ask a coroutine to
488end itself, although there is no guarentee that the exception will lead to
489termination, and if the exception isn't caught it might well end the whole
490program.
471 491
472=cut 492=cut
473 493
474sub desc { 494sub desc {
475 my $old = $_[0]{desc}; 495 my $old = $_[0]{desc};
593 to allow per-thread schedulers, but Coro::State does not yet allow 613 to allow per-thread schedulers, but Coro::State does not yet allow
594 this). 614 this).
595 615
596=head1 SEE ALSO 616=head1 SEE ALSO
597 617
598Support/Utility: L<Coro::Cont>, L<Coro::Specific>, L<Coro::State>, L<Coro::Util>. 618Support/Utility: L<Coro::Specific>, L<Coro::State>, L<Coro::Util>.
599 619
600Locking/IPC: L<Coro::Signal>, L<Coro::Channel>, L<Coro::Semaphore>, L<Coro::SemaphoreSet>, L<Coro::RWLock>. 620Locking/IPC: L<Coro::Signal>, L<Coro::Channel>, L<Coro::Semaphore>, L<Coro::SemaphoreSet>, L<Coro::RWLock>.
601 621
602Event/IO: L<Coro::Timer>, L<Coro::Event>, L<Coro::Handle>, L<Coro::Socket>, L<Coro::Select>. 622Event/IO: L<Coro::Timer>, L<Coro::Event>, L<Coro::Handle>, L<Coro::Socket>, L<Coro::Select>.
603 623

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines