Skip to content

Instantly share code, notes, and snippets.

@preaction
Last active April 24, 2016 23:09
Show Gist options
  • Select an option

  • Save preaction/b60c0d0fc960f9072d27e71b05375939 to your computer and use it in GitHub Desktop.

Select an option

Save preaction/b60c0d0fc960f9072d27e71b05375939 to your computer and use it in GitHub Desktop.
Mojo::IOLoop::Delay->new->steps(
sub {
my ( $delay ) = @_;
$db->query( '...', cb => $delay->begin );
$db->query( '...', cb => $delay->begin );
},
sub {
my ( $delay, @results ) = @_;
$c->render( ... );
},
)->wait;
my $delay = Mojo::IOLoop::Delay->new;
$db->query( '...', cb => $delay->begin );
$db->query( '...', cb => $delay->begin );
$delay->on( 'finish' => sub {
my ( $delay, @args ) = @_;
$c->render( @args );
} );
$delay->wait;
my @collected = ();
my $waiting = 0;
$db->query( '...', cb => sub {
my ( $db, @args ) = @_;
push @collected, @args;
$waiting--;
} );
$waiting++;
$db->query( '...', cb => sub {
my ( $db, @args ) = @_;
push @collected, @args;
$waiting--;
} );
$waiting++;
Mojo::IOLoop->one_tick until $waiting == 0;
$c->render( @collected );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment