Skip Menu |
 

This queue is for tickets about the future CPAN distribution.

Report information
The Basics
Id: 131094
Status: open
Priority: 0/
Queue: future

People
Owner: Nobody in particular
Requestors: felipe [...] felipegasper.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: then() seems incorrectly documented
Date: Wed, 27 Nov 2019 05:43:50 -0500
To: bug-future [...] rt.cpan.org
From: Felipe Gasper <felipe [...] felipegasper.com>
Download (untitled) / with headers
text/plain 1.1k
Currently the POD says: ----- then (2 arguments) $future = $f1->then( \&done_code, \&fail_code ) The then method can also be passed the $fail_code block as well, giving a combination of then and else behaviour. This operation is designed to be compatible with the semantics of other future systems, such as Javascript's Q or Promises/A libraries. ----- … yet this isn’t how then() works, as a quick example shows: ----- perl -MFuture -e'my $f = Future->done(123); my $f2 = $f->then( sub { print 123 } )->then( sub { print 456 } )' 123 ----- It should print “123456”, but instead it only prints “123”. A quick comparison with node.js’s implementation: ----- Show quoted text
> Promise.resolve(123).then( () => console.log(123) ).then( () => console.log(234) );
Promise { <pending> } Show quoted text
> 123
234 ----- If Future::then() is described as “compatible” with Promise/A, I would think it would obey the same semantics and immediately resolve the returned Future. Given, though, that Future is already widely used, I assume that its current functionality is as intended; hence, the documentation should indicate what Future::then() does differently from then() on promises. Thank you! -FG
Download (untitled) / with headers
text/plain 691b
On Wed Nov 27 06:28:37 2019, felipe@felipegasper.com wrote: Show quoted text
> perl -MFuture -e'my $f = Future->done(123); my $f2 = $f->then( sub { > print 123 } )->then( sub { print 456 } )' > 123
Oh this is awkward. That's supposed to print an error that the first `then` block didn't return a Future. Instead nothing happened - the error has gone missing :( In any case, as every chaining code block is supposed to yield a Future, your example didn't do that so it doesn't run properly. Instead: $ perl -Mwarnings -MFuture -e'my $f = Future->done(123); my $f2 = $f->then( sub { print 123; Future->done } )->then( sub { print 456 } )' 123456 I'll investigate why the error went missing -- Paul Evans
Download (untitled) / with headers
text/plain 1.1k
On Wed Nov 27 08:11:12 2019, PEVANS wrote: Show quoted text
> On Wed Nov 27 06:28:37 2019, felipe@felipegasper.com wrote:
> > perl -MFuture -e'my $f = Future->done(123); my $f2 = $f->then( sub { > > print 123 } )->then( sub { print 456 } )' > > 123
> > Oh this is awkward. That's supposed to print an error that the first > `then` block didn't return a Future. Instead nothing happened - the > error has gone missing :(
Ohright; it's not thrown as an inline error, but instead becomes the failure state of the returned Future. Since you just discarded that, it doesn't appear. Try ->get'ing it: $ perl -Mwarnings -MFuture -e'my $f = Future->done(123); my $f2 = $f->then( sub { print 123 } )->then( sub { print 456 } )->get' Expected __ANON__(-e line 1) to return a Future at -e line 1. 123 $ perl -Mwarnings -MFuture -e'my $f = Future->done(123); my $f2 = $f->then( sub { print 123; Future->done } )->then( sub { print 456 } )->get' Expected __ANON__(-e line 1) to return a Future at -e line 1. 123456 $ perl -Mwarnings -MFuture -e'my $f = Future->done(123); my $f2 = $f->then( sub { print 123; Future->done } )->then( sub { print 456; Future->done } )->get' 123456 -- Paul Evans
Subject: Re: [rt.cpan.org #131094] then() seems incorrectly documented
Date: Wed, 27 Nov 2019 08:49:04 -0500
To: bug-future [...] rt.cpan.org
From: Felipe Gasper <felipe [...] felipegasper.com>
Download (untitled) / with headers
text/plain 1.2k
Show quoted text
> Le 27 nov. 2019 à 08:14, Paul Evans via RT <bug-future@rt.cpan.org> a écrit : > > Ohright; it's not thrown as an inline error, but instead becomes the failure state of the returned Future. Since you just discarded that, it doesn't appear. Try ->get'ing it: > > $ perl -Mwarnings -MFuture -e'my $f = Future->done(123); my $f2 = $f->then( sub { print 123 } )->then( sub { print 456 } )->get' > Expected __ANON__(-e line 1) to return a Future at -e line 1. > 123 > > $ perl -Mwarnings -MFuture -e'my $f = Future->done(123); my $f2 = $f->then( sub { print 123; Future->done } )->then( sub { print 456 } )->get' > Expected __ANON__(-e line 1) to return a Future at -e line 1. > 123456 > > $ perl -Mwarnings -MFuture -e'my $f = Future->done(123); my $f2 = $f->then( sub { print 123; Future->done } )->then( sub { print 456; Future->done } )->get' > 123456
Ah, thank you for clarifying! Mostly what I’m getting at, though, is that this interface appears to work quite differently from then() as promise objects implement it. With promises, the return from the then() callback is given to the next promise down the chain, and only if the then() callback throws/dies is the returned promise a failure. That being the case, should the documentation be updated to describe a bit more fully what Future::then() does? Thank you!


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.