… | |
… | |
50 | |
50 | |
51 | our $idle; # idle handler |
51 | our $idle; # idle handler |
52 | our $main; # main coroutine |
52 | our $main; # main coroutine |
53 | our $current; # current coroutine |
53 | our $current; # current coroutine |
54 | |
54 | |
55 | our $VERSION = '4.0'; |
55 | our $VERSION = '4.03'; |
56 | |
56 | |
57 | our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub); |
57 | our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub); |
58 | our %EXPORT_TAGS = ( |
58 | our %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 | ); |
… | |
… | |
255 | _pool_2 $cb; |
255 | _pool_2 $cb; |
256 | &schedule; |
256 | &schedule; |
257 | } |
257 | } |
258 | }; |
258 | }; |
259 | |
259 | |
260 | last if $@ eq "\3terminate\2\n"; |
260 | last if $@ eq "\3async_pool terminate\2\n"; |
261 | warn $@ if $@; |
261 | warn $@ if $@; |
262 | } |
262 | } |
263 | } |
263 | } |
264 | |
264 | |
265 | sub async_pool(&@) { |
265 | sub async_pool(&@) { |
… | |
… | |
470 | Sets (or gets in case the argument is missing) the description for this |
470 | Sets (or gets in case the argument is missing) the description for this |
471 | coroutine. This is just a free-form string you can associate with a coroutine. |
471 | coroutine. This is just a free-form string you can associate with a coroutine. |
472 | |
472 | |
473 | This method simply sets the C<< $coroutine->{desc} >> member to the given string. You |
473 | This method simply sets the C<< $coroutine->{desc} >> member to the given string. You |
474 | can modify this member directly if you wish. |
474 | can modify this member directly if you wish. |
|
|
475 | |
|
|
476 | =item $coroutine->throw ([$scalar]) |
|
|
477 | |
|
|
478 | If C<$throw> is specified and defined, it will be thrown as an exception |
|
|
479 | inside the coroutine at the next convinient point in time (usually after |
|
|
480 | it gains control at the next schedule/transfer/cede). Otherwise clears the |
|
|
481 | exception object. |
|
|
482 | |
|
|
483 | The exception object will be thrown "as is" with the specified scalar in |
|
|
484 | C<$@>, i.e. if it is a string, no line number or newline will be appended |
|
|
485 | (unlike with C<die>). |
|
|
486 | |
|
|
487 | This can be used as a softer means than C<cancel> to ask a coroutine to |
|
|
488 | end itself, although there is no guarentee that the exception will lead to |
|
|
489 | termination, and if the exception isn't caught it might well end the whole |
|
|
490 | program. |
475 | |
491 | |
476 | =cut |
492 | =cut |
477 | |
493 | |
478 | sub desc { |
494 | sub desc { |
479 | my $old = $_[0]{desc}; |
495 | my $old = $_[0]{desc}; |