Future-Buffer

 view release on metacpan or  search on metacpan

lib/Future/Buffer.pm  view on Meta::CPAN

#
#  (C) Paul Evans, 2020-2024 -- leonerd@leonerd.org.uk

package Future::Buffer 0.06;

use v5.14;
use warnings;

use Future;

use Scalar::Util qw( weaken );

=head1 NAME

C<Future::Buffer> - a string buffer that uses Futures

=head1 SYNOPSIS

   use Future::Buffer;

   use Future::AsyncAwait;

lib/Future/Buffer.pm  view on Meta::CPAN

{
   my $self = shift;

   return $self->{fill_f} if $self->{fill_f};

   my $fill = $self->{fill};

   # Arm the fill loop
   my $f = $self->{fill_f} = $fill->(); # TODO: give it a size hint?

   weaken( my $weakself = $self );

   $f->on_done( sub {
      my $self = $weakself or return;

      undef $self->{fill_f};

      if( @_ ) {
         my ( $data ) = @_;
         $self->{data} .= $data;
      }



( run in 0.852 second using v1.01-cache-2.11-cpan-65fba6d93b7 )