Subject: | Cyclic reference in then() |
I ran the attached test (future_cycle.t) and found there is a cyclic reference in Futures when then() method is called and some of the futures are pending.
I modified Future.pm (attached) so that futures in @{$self->{on_cancel}} are weak-refs. It passed the future_cycle.t test.
However, the modified version fails t/06followed_by.t, which seems to claim there SHOULD be a cyclic ref.
So my question is, is it your intension to create the cyclic ref?
Subject: | Future.pm |
Message body is not shown because it is too large.
Subject: | future_cycle.t |
use strict;
use warnings;
use Test::More;
use Test::Memory::Cycle;
use Future;
{
note("--- pending f1, immediate f2");
my $f1 = Future->new;
my $f2 = Future->new->done;
my $next = $f1->then(sub { Future->new->done() });
memory_cycle_ok $f1, "f1=pending, f2=resolved, no cycle at f1";
memory_cycle_ok $f2, "f1=pending, f2=resolved, no cycle at f2";
memory_cycle_ok $next, "f1=pending, f2=resolved, no cycle at next";
$f1->done;
memory_cycle_ok $f1, "f1=resolved, f2=resolved, no cycle at f1";
memory_cycle_ok $f2, "f1=resolved, f2=resolved, no cycle at f2";
memory_cycle_ok $next, "f1=resolved, f2=resolved, no cycle at next";
}
{
note("--- immediate f1, pending f2");
my $f1 = Future->new->done;
my $f2 = Future->new;
my $next = $f1->then(sub { $f2 });
memory_cycle_ok $f1, "f1=resolved, f2=pending, no cycle at f1";
memory_cycle_ok $f2, "f1=resolved, f2=pending, no cycle at f2";
memory_cycle_ok $next, "f1=resolved, f2=pending, no cycle at next";
$f2->done;
memory_cycle_ok $f1, "f1=resolved, f2=resolved, no cycle at f1";
memory_cycle_ok $f2, "f1=resolved, f2=resolved, no cycle at f2";
memory_cycle_ok $next, "f1=resolved, f2=resolved, no cycle at next";
}
{
note("--- pending f1, pending f2");
my $f1 = Future->new;
my $f2 = Future->new;
my $next = $f1->then(sub { $f2 });
memory_cycle_ok $f1, "f1=pending, f2=pending, no cycle at f1";
memory_cycle_ok $f2, "f1=pending, f2=pending, no cycle at f2";
memory_cycle_ok $next, "f1=pending, f2=pending, no cycle at next";
$f1->done;
memory_cycle_ok $f1, "f1=resolved, f2=pending, no cycle at f1";
memory_cycle_ok $f2, "f1=resolved, f2=pending, no cycle at f2";
memory_cycle_ok $next, "f1=resolved, f2=pending, no cycle at next";
$f2->done;
memory_cycle_ok $f1, "f1=resolved, f2=resolved, no cycle at f1";
memory_cycle_ok $f2, "f1=resolved, f2=resolved, no cycle at f2";
memory_cycle_ok $next, "f1=resolved, f2=resolved, no cycle at next";
}
{
note("--- immediate f1, immediate f2");
my $f1 = Future->new->done;
my $f2 = Future->new->done;
my $next = $f1->then(sub { $f2 });
memory_cycle_ok $f1, "f1=resolved, f2=resolved, no cycle at f1";
memory_cycle_ok $f2, "f1=resolved, f2=resolved, no cycle at f2";
memory_cycle_ok $next, "f1=resolved, f2=resolved, no cycle at next";
}
done_testing;