… | |
… | |
573 | callback) and B<done> (request has reached the end of its lifetime and |
573 | callback) and B<done> (request has reached the end of its lifetime and |
574 | holds no resources anymore). |
574 | holds no resources anymore). |
575 | |
575 | |
576 | =over 4 |
576 | =over 4 |
577 | |
577 | |
578 | =item $req->cancel |
578 | =item cancel $req |
579 | |
579 | |
580 | Cancels the request, if possible. Has the effect of skipping execution |
580 | Cancels the request, if possible. Has the effect of skipping execution |
581 | when entering the B<execute> state and skipping calling the callback when |
581 | when entering the B<execute> state and skipping calling the callback when |
582 | entering the the B<result> state, but will leave the request otherwise |
582 | entering the the B<result> state, but will leave the request otherwise |
583 | untouched. That means that requests that currently execute will not be |
583 | untouched. That means that requests that currently execute will not be |
584 | stopped and resources held by the request will not be freed prematurely. |
584 | stopped and resources held by the request will not be freed prematurely. |
585 | |
585 | |
|
|
586 | =item cb $req $callback->(...) |
|
|
587 | |
|
|
588 | Replace (or simply set) the callback registered to the request. |
|
|
589 | |
586 | =back |
590 | =back |
587 | |
591 | |
588 | =head2 IO::AIO::GRP CLASS |
592 | =head2 IO::AIO::GRP CLASS |
589 | |
593 | |
590 | This class is a subclass of L<IO::AIO::REQ>, so all its methods apply to |
594 | This class is a subclass of L<IO::AIO::REQ>, so all its methods apply to |
… | |
… | |
647 | group. And only when all those requests have finished will the the group |
651 | group. And only when all those requests have finished will the the group |
648 | itself finish. |
652 | itself finish. |
649 | |
653 | |
650 | =over 4 |
654 | =over 4 |
651 | |
655 | |
|
|
656 | =item add $grp ... |
|
|
657 | |
652 | =item $grp->add (...) |
658 | =item $grp->add (...) |
653 | |
|
|
654 | =item add $grp ... |
|
|
655 | |
659 | |
656 | Add one or more requests to the group. Any type of L<IO::AIO::REQ> can |
660 | Add one or more requests to the group. Any type of L<IO::AIO::REQ> can |
657 | be added, including other groups, as long as you do not create circular |
661 | be added, including other groups, as long as you do not create circular |
658 | dependencies. |
662 | dependencies. |
659 | |
663 | |
… | |
… | |
662 | =item $grp->result (...) |
666 | =item $grp->result (...) |
663 | |
667 | |
664 | Set the result value(s) that will be passed to the group callback when all |
668 | Set the result value(s) that will be passed to the group callback when all |
665 | subrequests have finished. By default, no argument will be passed. |
669 | subrequests have finished. By default, no argument will be passed. |
666 | |
670 | |
667 | =item $grp->set_feeder ($callback->($grp)) |
671 | =item feed $grp $callback->($grp) |
668 | |
672 | |
669 | [VERY EXPERIMENTAL] |
673 | [VERY EXPERIMENTAL] |
670 | |
674 | |
671 | Sets a feeder/generator on this group: every group can have an attached |
675 | Sets a feeder/generator on this group: every group can have an attached |
672 | generator that generates requests if idle. The idea behind this is that, |
676 | generator that generates requests if idle. The idea behind this is that, |
… | |
… | |
675 | example, C<aio_scandir> might generate hundreds of thousands C<aio_stat> |
679 | example, C<aio_scandir> might generate hundreds of thousands C<aio_stat> |
676 | requests, delaying any later requests for a long time. |
680 | requests, delaying any later requests for a long time. |
677 | |
681 | |
678 | To avoid this, and allow incremental generation of requests, you can |
682 | To avoid this, and allow incremental generation of requests, you can |
679 | instead a group and set a feeder on it that generates those requests. The |
683 | instead a group and set a feeder on it that generates those requests. The |
680 | feeder will be called whenever there are few enough (see C<feeder_limit>, |
684 | feed callback will be called whenever there are few enough (see C<feed_limit>, |
681 | below) requests active in the group itself and is expected to queue more |
685 | below) requests active in the group itself and is expected to queue more |
682 | requests. |
686 | requests. |
683 | |
687 | |
684 | The feeder can queue as many requests as it likes (i.e. C<add> does not |
688 | The feed can queue as many requests as it likes (i.e. C<add> does not |
685 | impose any limits). |
689 | impose any limits). |
686 | |
690 | |
687 | If the feeder does not queue more requests when called, it will be |
691 | If the feed does not queue more requests when called, it will be |
688 | automatically removed from the group. |
692 | automatically removed from the group. |
689 | |
693 | |
690 | If the feeder limit is C<0>, it will be set to C<2> automatically. |
694 | If the feed limit is C<0>, it will be set to C<2> automatically. |
691 | |
695 | |
692 | Example: |
696 | Example: |
693 | |
697 | |
694 | # stat all files in @files, but only ever use four aio requests concurrently: |
698 | # stat all files in @files, but only ever use four aio requests concurrently: |
695 | |
699 | |
696 | my $grp = aio_group sub { print "finished\n" }; |
700 | my $grp = aio_group sub { print "finished\n" }; |
697 | $grp->feeder_limit (4); |
701 | feed_limit $grp 4; |
698 | $grp->set_feeder (sub { |
702 | feed $grp sub { |
699 | my $file = pop @files |
703 | my $file = pop @files |
700 | or return; |
704 | or return; |
701 | |
705 | |
702 | add $grp aio_stat $file, sub { ... }; |
706 | add $grp aio_stat $file, sub { ... }; |
703 | }); |
707 | }; |
704 | |
708 | |
705 | =item $grp->feeder_limit ($num) |
709 | =item feed_limit $grp $num |
706 | |
710 | |
707 | Sets the feeder limit for the group: The feeder will be called whenever |
711 | Sets the feeder limit for the group: The feeder will be called whenever |
708 | the group contains less than this many requests. |
712 | the group contains less than this many requests. |
709 | |
713 | |
710 | Setting the limit to C<0> will pause the feeding process. |
714 | Setting the limit to C<0> will pause the feeding process. |