Skip to content

Instantly share code, notes, and snippets.

@esobchenko
Created December 19, 2018 22:04
Show Gist options
  • Save esobchenko/6377806acead3c543c3ef3db9bc4900f to your computer and use it in GitHub Desktop.
Save esobchenko/6377806acead3c543c3ef3db9bc4900f to your computer and use it in GitHub Desktop.
Mojo IOLoop synchronization example
use strict;
use warnings;
use v5.10;
use Mojo::UserAgent;
use Mojo::IOLoop;
use Data::Dumper;
my $delay = Mojo::IOLoop->delay(sub { shift; say Dumper([@_]); });
for my $i (1 .. 3) {
my $end = $delay->begin;
Mojo::IOLoop->timer($i => sub {
$delay->pass( "step $i" );
$end->();
});
}
$delay->wait;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment