The difference is that $c->ua does not go out of scope. $ua =
Mojo::UserAgent->new need to be kept "alive" manually. Example:
# this will never complete, because $ua gets garbage collected:
get "/foo" => sub {
my $c = shift;
my $ua = Mojo::UserAgent->new;
$ua->get("example.com" => sub { ... });
};
# this on the other hand works:
get "/foo" => sub {
my $c = shift;
my $ua = Mojo::UserAgent->new;
$self->stash(my_ua => $ua);
$ua->get("example.com" => sub { ... });
};
Also, You don't have to create more Mojo::UserAgent object. The same ua
object can do all the requests.
On Sunday, July 27, 2014 12:42:36 PM UTC+2, Andrey Khozov wrote:
>
> Can you explain what is the difference between
>
> my $ua = $c->ua;
>
> and
>
> my $ua = Mojo::UserAgent->new(server => Mojo::UserAgent::Server->new(app
> => $c->app));
>
> in controller? (except weaken reference to app)
>
>
> On Fri, Jul 25, 2014 at 7:09 PM, Andrey Khozov <[email protected]>
> wrote:
>
>> Yes, I see this. But in this case client should wait while user agent
>> processing requests (while delay is not finished) ?
>>
>>
>> P.S. links with anchor broken for now.
>>
>>
>> On Fri, Jul 25, 2014 at 7:01 PM, sri <[email protected]> wrote:
>>
>>>
>>> http://mojolicio.us/perldoc/Mojolicious/Guides/FAQ#What_does_\%22Premature_connection_close\%22_mean\%3F
>>>
>>> <http://mojolicio.us/perldoc/Mojolicious/Guides/FAQ#What_does_%5C%22Premature_connection_close%5C%22_mean%5C%3F>
>>>
>>> --
>>> sebastian
>>>
>>
>>
>>
>> --
>> Andrey Khozov
>>
>
>
>
> --
> Andrey Khozov
>
--
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 http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.