Subject: | $deferred->resolve($promise) neglects to resolve a promise |
Date: | Wed, 18 Dec 2019 12:26:45 -0500 |
To: | bug-AnyEvent-XSPromises [...] rt.cpan.org |
From: | Felipe Gasper <felipe [...] felipegasper.com> |
=====
#!/usr/bin/env perl
use strict;
use warnings;
use AnyEvent::XSPromises ();
use Data::Dumper;
my $cv = AnyEvent->condvar();
my $deferred1 = AnyEvent::XSPromises::deferred();
my $p = $deferred1->promise();
my $pp = $p->then( sub { print Dumper( promise1 => shift ); $cv->(); } );
my $deferred2 = AnyEvent::XSPromises::deferred();
my $p2 = $deferred2->promise();
$deferred1->resolve($p2);
$cv->recv();
=====
Show quoted text
> perl anyevent_xspromises_bug.pl
$VAR1 = 'promise1';
$VAR2 = bless( do{\(my $o = '140656308834288')}, 'AnyEvent::XSPromises::PromisePtr' );
---------
Compare to the following JS code, which shows that a promise given to the resolve callback/function is itself resolved; that resolution, not the promise itself, is what is given to the on-resolve handler:
=====
#!/usr/bin/env node
"use strict";
var res;
var p = new Promise( (y) => { res = y } );
var res2;
var p2 = new Promise( (y) => { res2 = y } );
res(p2);
p.then( (v) => console.log("got", v) );
res2( Promise.resolve(234) );
=====
Show quoted text> node promise.js
got 234
---------
Thank you in advance for looking into this!
-Felipe Gasper