Subject: | Attempting to mark as ->done when cancelling repeat { } |
Seems that calling ->cancel on a repeat {} block can cause things to be marked as done. Does the attached test case look valid?
This is from a larger piece of code which uses timeouts to cancel various actions, the 'already cancelled and cannot be ->done' error seems to crop up every now and then and I *think* this is the cause.
# Repeat cycle
ok 1 - mark trial as done
# Cancel repeat future
# Repeat cycle
ok 2 - can cancel repeat future
# Repeat cycle
Future=HASH(0xf1ae08) is already cancelled and cannot be ->done at .../Future.pm line 565.
Future::done(Future=HASH(0xf1ae08)) called at .../Future.pm line 837
Future::on_done(Future=HASH(0xf2ecf8), Future=HASH(0xf1ae08)) called at .../Future/Utils.pm line 204
Future::Utils::_repeat(CODE(0xa24770), Future=HASH(0xf1ae08), REF(0xc3b8f0), CODE(0xf1ab20), 0) called at .../Future/Utils.pm line 196
Future::Utils::__ANON__(Future=HASH(0xf2ecf8)) called at .../Future.pm line 516
Future::_mark_ready(Future=HASH(0xf2ecf8)) called at .../Future.pm line 568
Future::done(Future=HASH(0xf2ecf8)) called at util-cancel.t line 14
cheers,
Tom
Subject: | util-cancel.t |
use strict;
use warnings;
use Test::More;
use Future;
use Future::Utils qw(repeat);
use IO::Async::Loop;
my $loop = IO::Async::Loop->new;
my $count = 3;
my $test = repeat {
my $f = Future->new;
$loop->later(sub {
ok($f->done, 'mark trial as done') unless $f->is_ready
});
$f
} while => sub {
note "Repeat cycle";
--$count
};
$loop->later(sub {
note "Cancel repeat future";
ok($test->cancel, 'can cancel repeat future');
});
$test->on_ready(sub { $loop->later(sub { $loop->stop }) });
$loop->run;
pass("Finished loop");
done_testing;