fs::Promises - Promises interface to nonblocking file system operations
use fs::Promises; use fs::Promises::Utils qw(await); # Fancy, but not really useful: my $fh = await +fs::Promises->open_promise($0); while ( my $line = await +fs::Promises->readline_promise($fh) ) { say $line; } # Same thing but using the functional interface: use fs::Promises qw(open_promise readline_promise); my $fh = await open_promise($0); while ( my $line = await readline_promise($fh) ) { say $line; } # Actuall async: use experimental 'signatures'; use fs::Promises qw(open_promise readline_promise); use fs::Promises::Utils qw(p_while); await +open_promise($0)->then(sub ($fh) { return p_while { readline_promise($fh) } sub ($line) { say $line; } }); # Reading four files in parallel: use experimental 'signatures'; use AnyEvent::XSPromises qw(collect); use fs::Promises qw(open_promise readline_promise); use fs::Promises::Utils qw(await p_while); my $read_file = sub ($fh) { return p_while { readline_promise($fh) } sub ($line) { say $line; } }; await +collect( open_promise($0)->then($read_file), open_promise($0)->then($read_file), open_promise($0)->then($read_file), open_promise($0)->then($read_file), );
fs::Promises is a promises layer around AnyEvent::AIO. If your code is using promises, then you can use this module to do fs-based stuff in an asynchronous way.
fs::Promises
To install fs::Promises, copy and paste the appropriate command in to your terminal.
cpanm
cpanm fs::Promises
CPAN shell
perl -MCPAN -e shell install fs::Promises
For more information on module installation, please visit the detailed CPAN module installation guide.