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> |
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