Created
July 21, 2021 09:31
-
-
Save maros/d9f5a8d1cc6d96f374f0c45e22e7ab0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
perl5: | |
use EV; | |
use Promises backend => ['EV'], qw(deferred); | |
use AnyEvent; | |
my $d1 = deferred(); | |
my $final = $d1->promise->then(sub($r) { | |
my $d2 = deferred(); | |
say 'GOT '.$r; # Should be TEST1 | |
my $timer; | |
$timer = AnyEvent->timer( | |
after => 2, | |
cb => sub { | |
$timer = undef; | |
$d2->resolve; | |
} | |
); | |
return $d2->promise; | |
})->then(sub($r) { | |
say 'GOT '.$r; # Should be TEST2 | |
}); | |
$d1->resolve('TEST1'); | |
my $c = AnyEvent->condvar; | |
collect($final) | |
->done( | |
sub { $c->send(@_); }, | |
sub { $c->croak(@_); }, | |
); | |
$c->recv; | |
javascript: | |
var p1 = new Promise(function(resolve) { resolve('Test1') }); | |
await p1.then((r) => { | |
console.log('GOT '+r); | |
return new Promise(function(resolve) { setTimeout(function(){ resolve('Test2') },2000) }) | |
}) | |
.then((r) => { | |
console.log('GOT '+r) | |
}); | |
console.log("DONE") | |
raku: | |
my $p1 = Promise.new(); | |
$p1.vow.keep("TEST1"); | |
await $p1.then({ | |
say "GOT " ~ .result; # expecting TEST1 | |
return Promise.in(2).then: { return "TEST2" }; | |
}).then({ | |
say $_.gist; # Promise, NOT "TEST2" | |
say "GOT" ~ .result; # expecting TEST2, but got exception | |
}); | |
say "DONE"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment