summaryrefslogtreecommitdiff
path: root/t/retain_future.t
blob: f30d8b05c64a78fe80ff190ac63567e968cfd9c1 (plain)
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
use strict;
use warnings;

use Test::More;
use Test::Refcount;
use Variable::Disposition qw(retain_future dispose);

unless(eval { require Future }) {
    plan skip_all => 'this test requires Future.pm';
}

for my $resolution (qw(done fail cancel)) {
    my $f = Future->new;
    is_refcount($f, 1, 'refcount is 1');
    retain_future($f);
    is_refcount($f, 2, 'refcount is now 2');
    $f->$resolution($resolution eq 'cancel' ? () : '...');
    is_refcount($f, 1, 'refcount is back to 1 after ' . $resolution);
    dispose($f);
    is($f, undef, 'goes away after dispose');
}

{
    ok(retain_future(Future->done), 'can retain ->done Future');
    ok(retain_future(Future->fail("...")), 'can retain ->failed Future');
    ok(retain_future(Future->new->cancel), 'can retain ->cancelled Future');
}


done_testing;