/**
  * {@inheritdoc}
  */
 protected function doSendInternalRequests(array $internalRequests)
 {
     if (!empty($internalRequests)) {
         $this->eventDispatcher->dispatch(Events::MULTI_REQUEST_CREATED, $multiRequestCreatedEvent = new MultiRequestCreatedEvent($this, $internalRequests));
         $internalRequests = $multiRequestCreatedEvent->getRequests();
     }
     $exceptions = array();
     try {
         $responses = parent::doSendInternalRequests($internalRequests);
     } catch (MultiHttpAdapterException $e) {
         $responses = $e->getResponses();
         $exceptions = $e->getExceptions();
     }
     if (!empty($responses)) {
         $this->eventDispatcher->dispatch(Events::MULTI_REQUEST_SENT, $requestSentEvent = new MultiRequestSentEvent($this, $responses));
         $exceptions = array_merge($exceptions, $requestSentEvent->getExceptions());
         $responses = $requestSentEvent->getResponses();
     }
     if (!empty($exceptions)) {
         $this->eventDispatcher->dispatch(Events::MULTI_REQUEST_ERRORED, $exceptionEvent = new MultiRequestErroredEvent($this, $exceptions));
         $responses = array_merge($responses, $exceptionEvent->getResponses());
         $exceptions = $exceptionEvent->getExceptions();
         if (!empty($exceptions)) {
             throw new MultiHttpAdapterException($exceptions, $responses);
         }
     }
     return $responses;
 }
 /**
  * On multi request errored event.
  *
  * @param \Ivory\HttpAdapter\Event\MultiRequestErroredEvent $event The multi request errored event.
  */
 public function onMultiResponseErrored(MultiRequestErroredEvent $event)
 {
     $retryRequests = array();
     foreach ($event->getExceptions() as $exception) {
         if (($request = $this->retry->retry($exception->getRequest(), false)) !== false) {
             $retryRequests[] = $request;
             $event->removeException($exception);
         }
     }
     if (empty($retryRequests)) {
         return;
     }
     try {
         $event->addResponses($event->getHttpAdapter()->sendRequests($retryRequests));
     } catch (MultiHttpAdapterException $e) {
         $event->addResponses($e->getResponses());
         $event->addExceptions($e->getExceptions());
     }
 }
 /**
  * On multi request errored event.
  *
  * @param \Ivory\HttpAdapter\Event\MultiRequestErroredEvent $event The multi request errored event.
  */
 public function onMultiResponseErrored(MultiRequestErroredEvent $event)
 {
     foreach ($event->getExceptions() as $exception) {
         if ($exception->hasResponse()) {
             $this->cookieJar->extract($exception->getRequest(), $exception->getResponse());
         }
     }
 }
 /**
  * On multi request errored event.
  *
  * @param \Ivory\HttpAdapter\Event\MultiRequestErroredEvent $event The multi request errored event.
  */
 public function onMultiResponseErrored(MultiRequestErroredEvent $event)
 {
     foreach ($event->getExceptions() as $exception) {
         $exception->setRequest($this->error($event->getHttpAdapter(), $exception));
     }
 }
 /**
  * On multi request errored event.
  *
  * @param \Ivory\HttpAdapter\Event\MultiRequestErroredEvent $event The multi request errored event.
  */
 public function onMultiResponseErrored(MultiRequestErroredEvent $event)
 {
     foreach ($event->getExceptions() as $exception) {
         $this->stopwatch->stop($this->getStopwatchName($event->getHttpAdapter(), $exception->getRequest()));
     }
 }