… | |
… | |
81 | |
81 | |
82 | our $idle; # idle handler |
82 | our $idle; # idle handler |
83 | our $main; # main coro |
83 | our $main; # main coro |
84 | our $current; # current coro |
84 | our $current; # current coro |
85 | |
85 | |
86 | our $VERSION = 5.25; |
86 | our $VERSION = 5.26; |
87 | |
87 | |
88 | our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub rouse_cb rouse_wait); |
88 | our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub rouse_cb rouse_wait); |
89 | our %EXPORT_TAGS = ( |
89 | our %EXPORT_TAGS = ( |
90 | prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)], |
90 | prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)], |
91 | ); |
91 | ); |
… | |
… | |
567 | wantarray ? @{$self->{_status}} : $self->{_status}[0]; |
567 | wantarray ? @{$self->{_status}} : $self->{_status}[0]; |
568 | } |
568 | } |
569 | |
569 | |
570 | =item $coro->on_destroy (\&cb) |
570 | =item $coro->on_destroy (\&cb) |
571 | |
571 | |
572 | Registers a callback that is called when this coro gets destroyed, |
572 | Registers a callback that is called when this coro thread gets destroyed, |
573 | but before it is joined. The callback gets passed the terminate arguments, |
573 | but before it is joined. The callback gets passed the terminate arguments, |
574 | if any, and I<must not> die, under any circumstances. |
574 | if any, and I<must not> die, under any circumstances. |
575 | |
575 | |
|
|
576 | There can be any number of C<on_destroy> callbacks per coro. |
|
|
577 | |
576 | =cut |
578 | =cut |
577 | |
579 | |
578 | sub on_destroy { |
580 | sub on_destroy { |
579 | my ($self, $cb) = @_; |
581 | my ($self, $cb) = @_; |
580 | |
582 | |
… | |
… | |
582 | } |
584 | } |
583 | |
585 | |
584 | =item $oldprio = $coro->prio ($newprio) |
586 | =item $oldprio = $coro->prio ($newprio) |
585 | |
587 | |
586 | Sets (or gets, if the argument is missing) the priority of the |
588 | Sets (or gets, if the argument is missing) the priority of the |
587 | coro. Higher priority coro get run before lower priority |
589 | coro thread. Higher priority coro get run before lower priority |
588 | coro. Priorities are small signed integers (currently -4 .. +3), |
590 | coros. Priorities are small signed integers (currently -4 .. +3), |
589 | that you can refer to using PRIO_xxx constants (use the import tag :prio |
591 | that you can refer to using PRIO_xxx constants (use the import tag :prio |
590 | to get then): |
592 | to get then): |
591 | |
593 | |
592 | PRIO_MAX > PRIO_HIGH > PRIO_NORMAL > PRIO_LOW > PRIO_IDLE > PRIO_MIN |
594 | PRIO_MAX > PRIO_HIGH > PRIO_NORMAL > PRIO_LOW > PRIO_IDLE > PRIO_MIN |
593 | 3 > 1 > 0 > -1 > -3 > -4 |
595 | 3 > 1 > 0 > -1 > -3 > -4 |
594 | |
596 | |
595 | # set priority to HIGH |
597 | # set priority to HIGH |
596 | current->prio (PRIO_HIGH); |
598 | current->prio (PRIO_HIGH); |
597 | |
599 | |
598 | The idle coro ($Coro::idle) always has a lower priority than any |
600 | The idle coro thread ($Coro::idle) always has a lower priority than any |
599 | existing coro. |
601 | existing coro. |
600 | |
602 | |
601 | Changing the priority of the current coro will take effect immediately, |
603 | Changing the priority of the current coro will take effect immediately, |
602 | but changing the priority of coro in the ready queue (but not |
604 | but changing the priority of a coro in the ready queue (but not running) |
603 | running) will only take effect after the next schedule (of that |
605 | will only take effect after the next schedule (of that coro). This is a |
604 | coro). This is a bug that will be fixed in some future version. |
606 | bug that will be fixed in some future version. |
605 | |
607 | |
606 | =item $newprio = $coro->nice ($change) |
608 | =item $newprio = $coro->nice ($change) |
607 | |
609 | |
608 | Similar to C<prio>, but subtract the given value from the priority (i.e. |
610 | Similar to C<prio>, but subtract the given value from the priority (i.e. |
609 | higher values mean lower priority, just as in unix). |
611 | higher values mean lower priority, just as in UNIX's nice command). |
610 | |
612 | |
611 | =item $olddesc = $coro->desc ($newdesc) |
613 | =item $olddesc = $coro->desc ($newdesc) |
612 | |
614 | |
613 | Sets (or gets in case the argument is missing) the description for this |
615 | Sets (or gets in case the argument is missing) the description for this |
614 | coro. This is just a free-form string you can associate with a |
616 | coro thread. This is just a free-form string you can associate with a |
615 | coro. |
617 | coro. |
616 | |
618 | |
617 | This method simply sets the C<< $coro->{desc} >> member to the given |
619 | This method simply sets the C<< $coro->{desc} >> member to the given |
618 | string. You can modify this member directly if you wish, and in fact, this |
620 | string. You can modify this member directly if you wish, and in fact, this |
619 | is often preferred to indicate major processing states that cna then be |
621 | is often preferred to indicate major processing states that cna then be |