Documentation

Pool
in package
implements PromisorInterface

Sends an iterator of requests concurrently using a capped pool size.

The pool will read from an iterator until it is cancelled or until the iterator is consumed. When a request is yielded, the request is sent after applying the "request_options" request options (if provided in the ctor).

When a function is yielded by the iterator, the function is provided the "request_options" array that should be merged on top of any existing options, and the function MUST then return a wait-able promise.

Tags
final

Interfaces, Classes, Traits and Enums

PromisorInterface
Interface used with classes that return a promise.

Table of Contents

$each  : EachPromise
__construct()  : mixed
batch()  : array<string|int, mixed>
Sends multiple requests concurrently and returns an array of responses and exceptions that uses the same ordering as the provided requests.
promise()  : PromiseInterface
Get promise
cmpCallback()  : void
Execute callback(s)

Properties

Methods

__construct()

public __construct(ClientInterface $client, array<string|int, mixed>|Iterator $requests[, array<string|int, mixed> $config = [] ]) : mixed
Parameters
$client : ClientInterface

Client used to send the requests.

$requests : array<string|int, mixed>|Iterator

Requests or functions that return requests to send concurrently.

$config : array<string|int, mixed> = []

Associative array of options

  • concurrency: (int) Maximum number of requests to send concurrently
  • options: Array of request options to apply to each request.
  • fulfilled: (callable) Function to invoke when a request completes.
  • rejected: (callable) Function to invoke when a request is rejected.
Return values
mixed

batch()

Sends multiple requests concurrently and returns an array of responses and exceptions that uses the same ordering as the provided requests.

public static batch(ClientInterface $client, array<string|int, mixed>|Iterator $requests[, array<string|int, mixed> $options = [] ]) : array<string|int, mixed>

IMPORTANT: This method keeps every request and response in memory, and as such, is NOT recommended when sending a large number or an indeterminate number of requests concurrently.

Parameters
$client : ClientInterface

Client used to send the requests

$requests : array<string|int, mixed>|Iterator

Requests to send concurrently.

$options : array<string|int, mixed> = []

Passes through the options available in Pool::__construct

Tags
throws
InvalidArgumentException

if the event format is incorrect.

Return values
array<string|int, mixed>

Returns an array containing the response or an exception in the same order that the requests were sent.

cmpCallback()

Execute callback(s)

private static cmpCallback(array<string|int, mixed> &$options, string $name, array<string|int, mixed> &$results) : void
Parameters
$options : array<string|int, mixed>
$name : string
$results : array<string|int, mixed>
Return values
void

Search results