jhthorsen / mojo-mysql

Mojolicious and Async MySQL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mojo::mysql + Mojo::Promise: code don't wait until finish requests

george-pmk opened this issue · comments

Under Mojolicious even simple example from the documentation

my $now = $db->query_p('select now() as now');
my $names = $db->query_p('select * from names');
Mojo::Promise->all($now, $names)->then(sub {
my ($now, $names) = @;
say $now->[0]->hash->{now};
say $
->{name} for $names->[0]->hashes->each;
})->catch(sub {
my $err = shift;
warn "Something went wrong: $err";
})->wait;

Mojo::IOLoop->start unless Mojo::IOLoop->is_running;

won't wait until queries are finished
the code passes the control on and I don't get any messages

What can I do to wait for all requests to finish?

wait() doesn't do anything when the loop is already running.

https://docs.mojolicious.org/Mojo/Promise#wait