… | |
… | |
520 | map [$_, sprintf "%s%04d", (/.\./ ? "1" : "0"), length], |
520 | map [$_, sprintf "%s%04d", (/.\./ ? "1" : "0"), length], |
521 | @$entries]; |
521 | @$entries]; |
522 | |
522 | |
523 | my (@dirs, @nondirs); |
523 | my (@dirs, @nondirs); |
524 | |
524 | |
525 | my ($statcb, $schedcb); |
|
|
526 | my $nreq = 0; |
|
|
527 | |
|
|
528 | my $statgrp = add $grp aio_group; |
525 | my $statgrp = add $grp aio_group sub { |
|
|
526 | $grp->result (\@dirs, \@nondirs); |
|
|
527 | }; |
529 | |
528 | |
530 | $schedcb = sub { |
529 | limit $statgrp $maxreq; |
531 | if (@$entries) { |
530 | feed $statgrp sub { |
532 | if ($nreq < $maxreq) { |
531 | return unless @$entries; |
533 | my $ent = pop @$entries; |
532 | my $entry = pop @$entries; |
|
|
533 | |
|
|
534 | add $statgrp aio_stat "$path/$entry/.", sub { |
|
|
535 | if ($_[0] < 0) { |
|
|
536 | push @nondirs, $entry; |
|
|
537 | } else { |
|
|
538 | # need to check for real directory |
|
|
539 | add $statgrp aio_lstat "$path/$entry", sub { |
|
|
540 | if (-d _) { |
|
|
541 | push @dirs, $entry; |
|
|
542 | |
|
|
543 | unless (--$ndirs) { |
|
|
544 | push @nondirs, @$entries; |
|
|
545 | feed $statgrp; |
|
|
546 | } |
|
|
547 | } else { |
|
|
548 | push @nondirs, $entry; |
|
|
549 | } |
534 | $nreq++; |
550 | } |
535 | add $statgrp aio_stat "$path/$ent/.", sub { $statcb->($_[0], $ent) }; |
|
|
536 | } |
551 | } |
537 | } elsif (!$nreq) { |
|
|
538 | # finished |
|
|
539 | $statgrp->cancel; |
|
|
540 | undef $statcb; |
|
|
541 | undef $schedcb; |
|
|
542 | $grp->result (\@dirs, \@nondirs); |
|
|
543 | } |
552 | }; |
544 | }; |
553 | }; |
545 | $statcb = sub { |
|
|
546 | my ($status, $entry) = @_; |
|
|
547 | |
|
|
548 | if ($status < 0) { |
|
|
549 | $nreq--; |
|
|
550 | push @nondirs, $entry; |
|
|
551 | &$schedcb; |
|
|
552 | } else { |
|
|
553 | # need to check for real directory |
|
|
554 | add $grp aio_lstat "$path/$entry", sub { |
|
|
555 | $nreq--; |
|
|
556 | |
|
|
557 | if (-d _) { |
|
|
558 | push @dirs, $entry; |
|
|
559 | |
|
|
560 | if (!--$ndirs) { |
|
|
561 | push @nondirs, @$entries; |
|
|
562 | $entries = []; |
|
|
563 | } |
|
|
564 | } else { |
|
|
565 | push @nondirs, $entry; |
|
|
566 | } |
|
|
567 | |
|
|
568 | &$schedcb; |
|
|
569 | } |
|
|
570 | } |
|
|
571 | }; |
|
|
572 | |
|
|
573 | &$schedcb while @$entries && $nreq < $maxreq; |
|
|
574 | }; |
554 | }; |
575 | }; |
555 | }; |
576 | }; |
556 | }; |
577 | |
557 | |
578 | $grp |
558 | $grp |
… | |
… | |
590 | |
570 | |
591 | If this call isn't available because your OS lacks it or it couldn't be |
571 | If this call isn't available because your OS lacks it or it couldn't be |
592 | detected, it will be emulated by calling C<fsync> instead. |
572 | detected, it will be emulated by calling C<fsync> instead. |
593 | |
573 | |
594 | =item aio_group $callback->(...) |
574 | =item aio_group $callback->(...) |
595 | |
|
|
596 | [EXPERIMENTAL] |
|
|
597 | |
575 | |
598 | This is a very special aio request: Instead of doing something, it is a |
576 | This is a very special aio request: Instead of doing something, it is a |
599 | container for other aio requests, which is useful if you want to bundle |
577 | container for other aio requests, which is useful if you want to bundle |
600 | many requests into a single, composite, request with a definite callback |
578 | many requests into a single, composite, request with a definite callback |
601 | and the ability to cancel the whole request with its subrequests. |
579 | and the ability to cancel the whole request with its subrequests. |
… | |
… | |
732 | be added, including other groups, as long as you do not create circular |
710 | be added, including other groups, as long as you do not create circular |
733 | dependencies. |
711 | dependencies. |
734 | |
712 | |
735 | Returns all its arguments. |
713 | Returns all its arguments. |
736 | |
714 | |
|
|
715 | =item $grp->cancel_subs |
|
|
716 | |
|
|
717 | Cancel all subrequests and clears any feeder, but not the group request |
|
|
718 | itself. Useful when you queued a lot of events but got a result early. |
|
|
719 | |
737 | =item $grp->result (...) |
720 | =item $grp->result (...) |
738 | |
721 | |
739 | Set the result value(s) that will be passed to the group callback when all |
722 | Set the result value(s) that will be passed to the group callback when all |
740 | subrequests have finished. By default, no argument will be passed. |
723 | subrequests have finished. By default, no argument will be passed. |
741 | |
724 | |
742 | =item feed $grp $callback->($grp) |
725 | =item feed $grp $callback->($grp) |
743 | |
|
|
744 | [VERY EXPERIMENTAL] |
|
|
745 | |
726 | |
746 | Sets a feeder/generator on this group: every group can have an attached |
727 | Sets a feeder/generator on this group: every group can have an attached |
747 | generator that generates requests if idle. The idea behind this is that, |
728 | generator that generates requests if idle. The idea behind this is that, |
748 | although you could just queue as many requests as you want in a group, |
729 | although you could just queue as many requests as you want in a group, |
749 | this might starve other requests for a potentially long time. For |
730 | this might starve other requests for a potentially long time. For |