namespace seekat\API\Call;
use AsyncInterop\Promise;
-use Exception;
use http\{
Client, Client\Request, Client\Response
};
use Psr\Log\LoggerInterface;
use seekat\API;
-use SplObserver;
-use SplSubject;
-final class Deferred implements SplObserver
+final class Deferred
{
/**
* The response importer
/* we did finish in the meantime */
$this->complete();
} else {
- $this->client->detach($this);
$this->client->dequeue($this->request);
($this->reject)("Cancelled");
}
$this->promise = $future->getPromise($context);
$this->resolve = API\Future\resolver($future, $context);
$this->reject = API\Future\rejecter($future, $context);
- $this->update = API\Future\updater($future, $context);
}
function __invoke() : Promise {
$this->response = $cached;
$this->complete();
} else {
- $this->client->attach($this);
$this->client->enqueue($this->request, function(Response $response) use($cached) {
if ($response->getResponseCode() == 304) {
$this->response = $cached;
return $this->promise;
}
- /**
- * Progress observer
- *
- * Import the response's data on success and resolve the promise.
- *
- * @param SplSubject $client The observed HTTP client
- * @param Request $request The request which generated the update
- * @param object $progress The progress information
- */
- function update(SplSubject $client, Request $request = null, $progress = null) {
- if ($request !== $this->request) {
- return;
- }
-
- ($this->update)((object) compact("client", "request", "progress"));
- }
-
/**
* Completion callback
- * @param callable $resolve
- * @param callable $reject
*/
private function complete() {
- $this->client->detach($this);
-
if ($this->response) {
try {
$api = ($this->result)($this->response);
$this->cache->save($this->request, $this->response);
($this->resolve)($api);
- } catch (Exception $e) {
+ } catch (\Throwable $e) {
($this->reject)($e);
}
} else {