Skip to content

Instantly share code, notes, and snippets.

/test.pl Secret

Created May 28, 2015 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/a83538e7a2e0e6d4d19f to your computer and use it in GitHub Desktop.
Save anonymous/a83538e7a2e0e6d4d19f to your computer and use it in GitHub Desktop.
# Sequential non-blocking selects
$db = $pg->db;
($fail, $result) = ();
Mojo::IOLoop->delay(
sub {
my $delay = shift;
$db->query('select 1 as one' => $delay->begin);
},
sub {
my ($delay, $err, $one) = @_;
$fail = $err;
push @$result, $one->hash;
$db->query('select 2 as two' => $delay->begin);
},
sub {
my ($delay, $err, $two) = @_;
$fail ||= $err;
push @$result, $two->hash;
}
)->wait;
ok !$fail, 'no error';
is_deeply $result, [{one => 1}, {two => 2}], 'right structure';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment