On Mon, Aug 06, 2018 at 09:45:44AM -0700, sri wrote:
>      $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;
}

Whzn I run the same "get_p" code in a script I run in command-line (without 
Mojlicious), I do not have the 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