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

Comparing IO-AIO/AIO.pm (file contents):
Revision 1.64 by root, Mon Oct 23 00:50:10 2006 UTC vs.
Revision 1.65 by root, Mon Oct 23 14:49:51 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines