Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use experimental 'signatures'; | ||
|
||
use FindBin; | ||
use lib "$FindBin::Bin/lib"; | ||
use Promise::ES6; | ||
|
||
use blib "$FindBin::Bin/Future-AsyncAwait-0.47"; | ||
|
||
use Future::AsyncAwait future_class => 'Promise::ES6'; | ||
|
||
use IO::Async::Loop; | ||
use IO::Async::Timer::Countdown; | ||
|
||
sub delay ($loop, $secs) { | ||
return Promise::ES6->new( sub ($res, @) { | ||
my $timer; $timer = IO::Async::Timer::Countdown->new( | ||
delay => $secs, | ||
on_expire => sub { | ||
undef $timer; | ||
$res->($secs); | ||
}, | ||
); | ||
|
||
$timer->start(); | ||
$loop->add($timer); | ||
} ); | ||
} | ||
|
||
async sub thethings ($loop) { | ||
print "waiting …\n"; | ||
|
||
my $waited_p = delay($loop, 0.2); | ||
|
||
my $waited = await $waited_p; | ||
|
||
print "waited $waited\n"; | ||
|
||
return 5; | ||
} | ||
|
||
#sub thethings_plain { | ||
# print "waiting …\n"; | ||
# return delay(3.2)->then( sub ($val) { | ||
# print "waited $val\n"; | ||
# 5; | ||
# } ); | ||
#} | ||
|
||
my $loop = IO::Async::Loop->new(); | ||
Promise::ES6::use_event('IO::Async', $loop); | ||
|
||
# It works thus: | ||
#my $promise1 = thethings($loop); | ||
#my $promise = $promise1->then( sub ($val) { | ||
|
||
my $promise = thethings($loop)->then( sub ($val) { | ||
print "async gave $val\n"; | ||
$loop->stop(); | ||
} ); | ||
|
||
$loop->run(); | ||
|
||
1; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use FindBin; | ||
use lib "$FindBin::Bin/lib"; | ||
use Promise::ES6; | ||
|
||
use Time::HiRes; | ||
|
||
#use blib "$FindBin::Bin/Future-AsyncAwait-0.47"; | ||
|
||
use Future::AsyncAwait future_class => 'Promise::ES6'; | ||
|
||
my $resolver_cr; | ||
my $p = Promise::ES6->new( sub { $resolver_cr = shift } ); | ||
|
||
async sub do_await { | ||
my $p = shift; | ||
return await $p; | ||
} | ||
|
||
do_await($p)->then( sub { print "got " . shift . $/ } ); | ||
|
||
Time::HiRes::sleep(0.1); | ||
|
||
$resolver_cr->(5); | ||
|
||
1; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Test::More; | ||
|
||
# This test throws unhandled-rejection warnings … do they matter? | ||
#use Test::FailWarnings; | ||
|
||
my $failed_why; | ||
|
||
BEGIN { | ||
eval 'use Test::Future::AsyncAwait::Awaitable; 1' or $failed_why = $@; | ||
} | ||
|
||
plan skip_all => "Can’t run test: $failed_why" if $failed_why; | ||
|
||
use Promise::ES6; | ||
|
||
Test::Future::AsyncAwait::Awaitable::test_awaitable( | ||
'Promise::ES6 conforms to Awaitable API', | ||
class => 'Promise::ES6', | ||
new => sub { Promise::ES6->new( sub {} ) }, | ||
); | ||
|
||
done_testing; |