NAME

Mojo::UserAgent::Role::PromiseClass - Choose the promise class used by Mojo::UserAgent

VERSION

version 0.007

SYNOPSIS

  $ua = Mojo::UserAgent->new(...)->with_roles('+PromiseClass');

  # add promise features you want
  $ua->promise_roles('+Repeat');

  # and they show up on every request promise
  $ua->get_p('http://example.com')->repeat(sub{...});

DESCRIPTION

Mojo::UserAgent::Role::PromiseClass is a role that allows specifying the promise class to be used for the promise-returning methods like "get_p" in UserAgent and "post_p" in UserAgent, if you want something different from Mojo::Promise.

Note that since most methods on Mojo::Promise will use clone to create new instances, roles assigned in this way will usually propagate down method chains. (As of version 8.25, the only places in core Mojolicious other than Mojo::UserAgent where promises are being created from scratch is "proxy->start_p" in Mojolicious::Plugin::DefaultHelpers and related helpers, which you would need to wrap if your application uses them.)

ATTRIBUTES

Mojo::UserAgent::Role::PromiseClass inherits the following attributes from Mojo::Base::Role::PromiseClass

promise_class

  $pclass = $ua->promise_class;
  $ua     = $ua->promise_class('Mojo::Promise');

Get or set the user agent's preferred promise class. This will be used for promises returned by start_p and all derived routines (get_p, post_p, ...).

For altering the promise class, you will more likely want to use promise_roles.

METHODS

Mojo::UserAgent::Role::PromiseClass inherits all methods from Mojo::Base::Role::PromiseClass.

SEE ALSO

Mojo::UserAgent, Mojo::Promise, Mojolicious, Mojolicious::Guides, https://mojolicious.org.

AUTHOR

Roger Crew <wrog@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2019 by Roger Crew.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)