DBIO-Forked

 view release on metacpan or  search on metacpan

t/02-future.t  view on Meta::CPAN

# pid is undef, so there is nothing to reap.

sub make_future {
  my ($payload, %opt) = @_;   # $payload: hashref to freeze, or undef to skip
  pipe(my $rh, my $wh) or die "pipe: $!";
  if (defined $payload) {
    print {$wh} Storable::freeze($payload);
    close $wh if !$opt{leave_open};
  }
  my $f = DBIO::Forked::Future->new(read_fh => $rh);
  return ($f, $wh);   # caller keeps $wh alive when leave_open
}

# --- success: is_ready true at EOF, get returns rows, idempotent ------------
{
  my ($f) = make_future({ rows => [ ['x'], ['y'] ] });
  ok($f->is_ready, 'is_ready true once a full blob is written and the pipe closed');
  ok(!$f->is_failed, 'is_failed false on success');
  is_deeply([ $f->get ], [ ['x'], ['y'] ], 'get returns the rows');
  is_deeply([ $f->get ], [ ['x'], ['y'] ], 'get is idempotent');
}



( run in 2.648 seconds using v1.01-cache-2.11-cpan-14f38c9f855 )