Le lundi 6 août 2018 18:45:44 UTC+2, sri a écrit :
>
>   $tx = $ua->start($tx);
>>
>
> Oh right, this is a blocking call, so you're just spinning in-place 
> appending chunks to the
> write buffer but never actually letting the event loop write to the 
> socket. You need to do it
> async.
>

I tried to use "start_p" or "get_p" but I get a "Premature connection 
close" error. I don't understand why. Here is the code of my sample 
Mojolicious controller :

package Foo2::Controller::Example;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::UserAgent;
use Mojo::Promise;


sub welcome {
  my $c = shift;
  my $ua = Mojo::UserAgent->new;
  $ua->get_p("https://www.mojolicious.org";)->then(sub {
    my $tx2 = shift;
    say $tx2->result->body;
  })->catch(sub {
    my $err = shift;
    warn "Connection error: $err";
  })->wait;
  $c->render_later;
}

When I run the same "get_p" code in a command-line script (without 
Mojlicious), I do not have this erro rmessage.

Alex

-- 
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