1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#!/usr/bin/perl
use v5.14;
use warnings;
use Test2::V0 0.000149;
use IO::Async::Notifier;
use Future;
my ( $err, $name, @detail );
my $notifier = IO::Async::Notifier->new(
on_error => sub {
( undef, $err, $name, @detail ) = @_;
},
);
# done
{
my $f = Future->new;
is( [ $notifier->adopted_futures ], [],
'->adopted_futures initially' );
$notifier->adopt_future( $f );
is_refcount( $f, 2, '$f has refcount 2 after ->adopt_future' );
is_oneref( $notifier, '$notifier still has refcount 1 after ->adopt_future' );
is( [ $notifier->adopted_futures ], [ $f ],
'->adopted_futures after adoption' );
$f->done( "result" );
is_refcount( $f, 1, '$f has refcount 1 after $f->done' );
is( [ $notifier->adopted_futures ], [],
'->adopted_futures finally' );
}
# fail
{
my $f = Future->new;
$notifier->adopt_future( $f );
$f->fail( "It failed", name => 1, 2, 3 );
is( $err, "It failed", '$err after $f->fail' );
is( $name, "name", '$name after $f->fail' );
is( \@detail, [ 1, 2, 3 ], '@detail after $f->fail' );
is_refcount( $f, 1, '$f has refcount 1 after $f->fail' );
undef $err;
$f = Future->new;
$notifier->adopt_future( $f->else_done() );
$f->fail( "Not captured" );
ok( !defined $err, '$err not defined after ->else_done suppressed failure' );
}
done_testing;
|