1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-25 02:22:57 +01:00

Adding a before callable to the sendAll method

This commit is contained in:
Michael Dowling 2014-01-01 17:56:37 -08:00
parent 0f502b598d
commit 805181d331
2 changed files with 10 additions and 16 deletions

View File

@ -209,28 +209,21 @@ class Client implements ClientInterface
{
$requests = function() use ($requests, $options) {
foreach ($requests as $request) {
/** @var RequestInterface $request */
if (isset($options['before'])) {
$request->getEventDispatcher()->addListener(RequestEvents::BEFORE_SEND, $options['before'], -255);
}
if (isset($options['complete'])) {
$request->getEventDispatcher()->addListener(
RequestEvents::AFTER_SEND,
$options['complete'],
-255
);
$request->getEventDispatcher()->addListener(RequestEvents::AFTER_SEND, $options['complete'], -255);
}
if (isset($options['error'])) {
$request->getEventDispatcher()->addListener(
RequestEvents::ERROR,
$options['error'],
-255
);
$request->getEventDispatcher()->addListener(RequestEvents::ERROR, $options['error'], -255);
}
yield new Transaction($this, $request);
}
};
$this->batchAdapter->batch(
$requests(),
isset($options['parallel']) ? $options['parallel'] : 50
);
$this->batchAdapter->batch($requests(), isset($options['parallel']) ? $options['parallel'] : 50);
}
/**

View File

@ -122,8 +122,9 @@ interface ClientInterface extends HasDispatcherInterface
* @param array|\Iterator $requests Requests to send in parallel
* @param array $options Associative array of options
* - parallel: (int) Max number of requests to send in parallel
* - complete: Callable that receives a RequestAfterSendEvent
* - error: Callable that receives a RequestErrorEvent
* - before: (callable) Receives a RequestBeforeSendEvent
* - complete: (callable) Receives a RequestAfterSendEvent
* - error: (callable) Receives a RequestErrorEvent
*/
public function sendAll($requests, array $options = []);