Skip Menu |

This queue is for tickets about the future CPAN distribution.

Report information
The Basics
Id: 85134
Status: resolved
Priority: 0/
Queue: future

People
Owner: Nobody in particular
Requestors: TEAM [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.12
Fixed in: 0.15



Subject: Return $self from ->on_cancel?
It'd be useful for symmetry to have ->on_cancel return $self, same as ->on_done / ->on_fail behaviour. At the moment: my $f = Future->new ->on_done(sub { ... }) ->on_fail(sub { ... }); works as expected, but: my $f = Future->new ->on_done(sub { ... }) ->on_fail(sub { ... }) ->on_cancel(sub { ... }); doesn't - $f ends up as either undef or 1 in the above example. cheers, Tom
On Wed May 08 06:32:27 2013, TEAM wrote: Show quoted text
> It'd be useful for symmetry to have ->on_cancel return $self, same as > ->on_done / ->on_fail behaviour.
Oops, easy one liner I missed. -- Paul Evans
Subject: rt85134.patch
=== modified file 'lib/Future.pm' --- lib/Future.pm 2013-04-01 18:54:22 +0000 +++ lib/Future.pm 2013-05-08 11:35:39 +0000 @@ -503,7 +503,10 @@ { my $self = shift; $self->is_ready and return; + push @{ $self->{on_cancel} }, @_; + + return $self; } =head2 $cancelled = $future->is_cancelled === modified file 't/02cancel.t' --- t/02cancel.t 2013-03-31 13:40:04 +0000 +++ t/02cancel.t 2013-05-08 11:35:39 +0000 @@ -5,6 +5,7 @@ use Test::More; use Test::Fatal; +use Test::Identity; use Future; @@ -14,7 +15,7 @@ my $cancelled; - $future->on_cancel( sub { $cancelled .= "1" } ); + identical( $future->on_cancel( sub { $cancelled .= "1" } ), $future, '->on_cancel returns $future' ); $future->on_cancel( sub { $cancelled .= "2" } ); my $ready;
On Wed May 08 07:36:23 2013, PEVANS wrote: Show quoted text
> On Wed May 08 06:32:27 2013, TEAM wrote:
> > It'd be useful for symmetry to have ->on_cancel return $self, same as > > ->on_done / ->on_fail behaviour.
> > Oops, easy one liner I missed.
Looks good, although maybe return $self in both branches? - $self->is_ready and return; + $self->is_ready and return $self; cheers, Tom
On Wed May 08 07:40:56 2013, TEAM wrote: Show quoted text
> - $self->is_ready and return; > + $self->is_ready and return $self;
Oops. Just got around to this now. Will be in 0.15 -- Paul Evans
Released in 0.15 -- Paul Evans