Hi.

You should return promise object in get_data sub. Something like:

my $get_data = sub {
  my $promise = Mojo::Promise->new();
  # Some code that resolves promise
  ...
  return $promise;
};

On Wednesday, 14 March 2018 12:18:07 UTC+2, Michael Fung wrote:
>
> Hi all,
>
> I have the following construct using Mojo::Promise:
>
> my $get_data =  sub {
>   create new Promise object;
>   read data from database
>   if data read ok {
>     $promise->resolve($data);
>   } else {
>     $promise->reject('no data');
>   }
> };
>
>
> $get_data->()
> ->then( sub {
>   # do something with data
>   ...
> })
> ->catch( sub {
>   # log error
>   ...
> })
> ->wait;
>
> say "the end";
>
> However, I got *"the end*" before running the "do something with data" 
> block or catch block. Is there any way to make ->wait really wait?
>
>
> Thanks,
> Michael
>
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to