File: retain_future.t

package info (click to toggle)
libvariable-disposition-perl 0.005-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 188 kB
  • sloc: perl: 196; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 818 bytes parent folder | download
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;