Created
November 3, 2017 16:25
-
-
Save diegok/90e42163abd4b2a1fe840487687c4cfa 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
use Mojo::Base -strict; | |
use Mojo::IOLoop; | |
my $promise = Mojo::IOLoop->delay; | |
Mojo::IOLoop->timer(2 => sub{ $promise->resolve(2) }); | |
$promise->then(sub{ | |
my $waited = shift; | |
my ($t1, $t3) = map { Mojo::IOLoop->delay } 1..2; | |
Mojo::IOLoop->timer(1 => sub{ $t1->resolve(1 + $waited) }); | |
Mojo::IOLoop->timer(3 => sub{ $t3->resolve(3 + $waited) }); | |
$t1->all($t3); | |
})->then(sub{ say "Done after $_[-1][0] seconds." })->wait; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment