--- IO-AIO/AIO.pm 2006/10/22 01:28:31 1.57 +++ IO-AIO/AIO.pm 2006/10/22 10:33:19 1.58 @@ -184,6 +184,8 @@ =item aio_move $srcpath, $dstpath, $callback->($status) +[EXPERIMENTAL due to internal aio_group use] + Try to move the I (directories not supported as either source or destination) from C<$srcpath> to C<$dstpath> and call the callback with the C<0> (error) or C<-1> ok. @@ -203,7 +205,7 @@ sub aio_move($$$) { my ($src, $dst, $cb) = @_; - my $grp = aio_group; + my $grp = aio_group $cb; add $grp aio_rename $src, $dst, sub { if ($_[0] && $! == EXDEV) { @@ -223,27 +225,27 @@ close $dst_fh; add $grp aio_unlink $src, sub { - $cb->($_[0]); + $grp->result ($_[0]); }; } else { my $errno = $!; add $grp aio_unlink $dst, sub { $! = $errno; - $cb->(-1); + $grp->result (-1); }; } }; } else { - $cb->(-1); + $grp->result (-1); } }, } else { - $cb->(-1); + $grp->result (-1); } }; } else { - $cb->($_[0]); + $grp->result ($_[0]); } }; @@ -345,6 +347,8 @@ =item aio_scandir $path, $maxreq, $callback->($dirs, $nondirs) +[EXPERIMENTAL due to internal aio_group use] + Scans a directory (similar to C) but additionally tries to separate the entries of directory C<$path> into two sets of names, ones you can recurse into (directories or links to them), and ones you cannot @@ -400,20 +404,20 @@ sub aio_scandir($$$) { my ($path, $maxreq, $cb) = @_; - my $grp = aio_group; + my $grp = aio_group $cb; $maxreq = 8 if $maxreq <= 0; # stat once add $grp aio_stat $path, sub { - return $cb->() if $_[0]; + return $grp->result () if $_[0]; my $now = time; my $hash1 = join ":", (stat _)[0,1,3,7,9]; # read the directory entries add $grp aio_readdir $path, sub { my $entries = shift - or return $cb->(); + or return $grp->result (); # stat the dir another time add $grp aio_stat $path, sub { @@ -428,7 +432,7 @@ # if nlink == 2, we are finished # on non-posix-fs's, we rely on nlink < 2 $ndirs = (stat _)[3] - 2 - or return $cb->([], $entries); + or return $grp->result ([], $entries); } # sort into likely dirs and likely nondirs @@ -454,7 +458,7 @@ # finished undef $statcb; undef $schedcb; - $cb->(\@dirs, \@nondirs) if $cb; + $grp->result (\@dirs, \@nondirs) if $cb; undef $cb; } }; @@ -507,7 +511,7 @@ If this call isn't available because your OS lacks it or it couldn't be detected, it will be emulated by calling C instead. -=item aio_group $callback->() +=item aio_group $callback->(...) [EXPERIMENTAL] @@ -587,7 +591,14 @@ $grp->add (aio_unlink "..."); - add $grp aio_stat "...", sub { ... }; + add $grp aio_stat "...", sub { + $_[0] or return $grp->result ("error"); + + # add another request dynamically, if first succeeded + add $grp aio_open "...", sub { + $grp->result ("ok"); + }; + }; This makes it very easy to create composite requests (see the source of C for an application) that work and feel like simple requests. @@ -622,6 +633,11 @@ Returns all its arguments. +=item $grp->result (...) + +Set the result value(s) that will be passed to the group callback when all +subrequests have finished. By default, no argument will be passed. + =back =head2 SUPPORT FUNCTIONS