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
|
#!/usr/bin/perl
use v5.14;
use warnings;
use Test2::V0;
use Test2::IPC; # to quiet the warning
use Future::XS;
eval { require Config && $Config::Config{useithreads} } or
plan skip_all => "This perl does not support threads";
require threads;
# Just to keep the in-dist unit tests happy; when loaded via Future.pm the
# one provided there takes precedence
sub Future::XS::wrap_cb
{
my $self = shift;
my ( $name, $cb ) = @_;
return $cb;
}
# future outside of thread
{
my $f1 = Future::XS->new;
my $f2 = $f1->then( sub { Future::XS->done( "result" ) } );
threads->create(sub {
return "dummy";
})->join;
$f1->done;
is( $f2->get, "result", 'Result of Future::XS entirely ouside of sidecar thread' );
}
# future inside thread
{
my $ret = threads->create(sub {
my $f1 = Future::XS->new;
my $f2 = $f1->then( sub { Future::XS->done( "result" ) } );
$f1->done;
return $f2->get;
})->join;
is( $ret, "result", 'Result of Future::XS entirely within thread' );
}
done_testing;
|