MojoX-HTTP-Async
view release on metacpan or search on metacpan
before dropping the connection.
inactivity_conn_ts
If last response was received inactivity_conn_ts seconds or more ago,
then such slots will be destroyed.
By default the value is 0 (disabled).
debug
Enables debug mode. The dbug messages will be printed in STDERR. By
default the value is 0 (disabled).
add ($self, $request_or_uri, $timeout = undef)
Adds HTTP request into empty slot.
If the request was successfully added, then it will return 1. Otherwise
it will return 0.
The request can be not added into slot only in case, if there are no
empty slots and new slot wasn't created due to the limit of slot's
amount had been reached (see new and slots.
It's recommendable always to check result code of this method.
Example:
my $ua = MojoX::HTTP::Async->new('host' => 'my-host.com', 'slots' => 1);
# let's occupy the only slot
$ua->add('/page1.html');
# let's wait until it's become free again
while ( ! $ua->add('/page2.html') ) {
while (my $tx = $ua->wait_for_next_response() ) {
# do something here
}
}
$request_or_uri
It can be either an instance of Mojo::Message::Request class, or an
instance of Mojo::URL. It also can be a simple URI srtring.
If the resourse contains the host, then it must be the same as in the
constructor new.
Using of string with URI or an instance of Mojo::URL class assumes
that GET HTTP method will be used.
$timeout
Time in seconds. Can be fractional with microseconds tolerance.
The request_timeout from conmtrucor will be used by default.
not_empty($self)
Returns 1 if there even one slot is busy or slot contains a not
processed response. Otherwise the method returns 0.
wait_for_next_response($self, $timeout = 0)
Waits for first received response or time-outed request in any slot.
Returns the Mojo::Transaction::HTTP instance with result.
$timeout
Period of time in seconds. Can be fractial with microsecond
tollerance. The response will be marked as time-outed after this time
is out.
The default value is 0, which means that request will have been
blocked until the response is received.
If all slots are empty, then undef will be returned.
next_response ($self)
Returns an instance of Mojo::Transaction::HTTP class. If there is no
response, it will return undef.
refresh_connections ($self)
Closes connections in slots in the following cases:
1. The slot was marked as timeouted
2. The "inactivity_conn_ts" was set and the connection was expired
3. There are some errors in socket (for example: Connection reset by peer, Broken pipe, etc)
Returns the amount of made reconnections.
close_all ($self)
Closes all opened connections and resets all slots with requests.
DESTROY($self)
The class destructor.
Closes all opened sockets.
( run in 0.852 second using v1.01-cache-2.11-cpan-39bf76dae61 )