Skip to content

Instantly share code, notes, and snippets.

@diegok
Created November 3, 2017 16:25
Show Gist options
  • Save diegok/90e42163abd4b2a1fe840487687c4cfa to your computer and use it in GitHub Desktop.
Save diegok/90e42163abd4b2a1fe840487687c4cfa to your computer and use it in GitHub Desktop.
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