Last active
April 24, 2016 23:09
-
-
Save preaction/b60c0d0fc960f9072d27e71b05375939 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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; |
This file contains hidden or 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
| 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; |
This file contains hidden or 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
| 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