private function sync() { if ($this->synchronized) { return; } /** @var ResponseInterface $clientResponse */ $clientResponse = $this->promise->wait(); if (200 !== $clientResponse->getStatusCode()) { throw new RemoteCallFailedException(); } $data = (string) $clientResponse->getBody(); // Null (empty response) is expected if only notifications were sent $rawResponses = []; if ('' !== $data) { $rawResponses = json_decode($data, false); if (json_last_error() !== JSON_ERROR_NONE) { throw ResponseParseException::notAJsonResponse(); } } if (!is_array($rawResponses) && $rawResponses instanceof \stdClass) { $rawResponses = [$rawResponses]; } $this->responses = []; foreach ($rawResponses as $rawResponse) { try { $response = new SyncResponse($rawResponse); } catch (ResponseParseException $exception) { //todo: logging??? (@scaytrase) continue; } $this->responses[$response->getId()] = $response; } $this->synchronized = true; }
protected function settlePromise() { if ($this->_promise) { $this->_promise->wait(false); $this->_promise = null; // not needed but let's be extra safe } }
/** * {@inheritdoc} */ public function wait($unwrap = true) { $this->promise->wait(false); if ($unwrap) { if ($this->getState() == self::REJECTED) { throw $this->exception; } return $this->response; } }
public function __construct(callable $generatorFn) { $this->generator = $generatorFn(); $this->result = new Promise(function () { while (isset($this->currentPromise)) { $this->currentPromise->wait(); } }); $this->nextCoroutine($this->generator->current()); }
/** * Waits for the operation to complete, when dealing with an asynchronous and incomplete operation. * * @throws \LogicException For unexpected exception not related to the SDK itself. */ public function wait() { /* The operation already completed, nothing to do. */ if ($this->isOperationComplete()) { return; } /* Wait for the response and unwrap it. */ try { $this->result = $this->wrapResult($this->promise->wait(true)); } catch (AwsException $e) { /* Set the response and exception. */ $this->result = null; $this->setupClientException($e); } }
/** * {@inheritdoc} */ public function wait() { $this->promise->wait(false); }
/** * This method waits for the promise to resolve and then proxies the result to the deferred * * @param Deferred $deferred * @param PromiseInterface $promise */ private function resolveOrRejectDeferredSync(Deferred $deferred, PromiseInterface $promise) { try { $response = $promise->wait(); $payload = $this->getPayloadFromResponse($response); $deferred->resolve($payload); } catch (\Exception $ex) { $deferred->reject($ex); } }