Hi! And thanks for answering! :-)
On 2015-11-18 09:30 AM, Paul Evans via RT wrote:
Show quoted text> This is intentional. You have to hold on to the tail-end of a Future chain, or it may well evaporate into thin air and you'll lose it.
>
> If the weaken wasn't there, you'd run the risk of easily creating far too many strong-cycle references. We tried that and it leads to mass amounts of memory leak. Best avoided.
>
> Any Future you create has to be held onto somehow - either by being the head end into another chain or convergence, calling ->get on it, or being stored strongly by some container system such as IO::Async's ->adopt_future.
I see. Hmmm... For something like my example, do you think the following
would be an acceptable way of going about it?
use Future;
use Test::More tests => 1;
my $first = Future->new;
sub Future::keep_alive {
# take the occasion to do house-keeping and
# remove all promises that are done, and thus
# don't need to be kept around
@Future::KeptAround = grep {
not $_->is_ready
} @Future::KeptAround, @_;
}
{
$first->then(sub{
Future->new->done
})->on_ready(sub{
pass
})->keep_alive;
}
$first->done;