X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=lib%2FAPI%2FDeferred.php;fp=lib%2FAPI%2FDeferred.php;h=0000000000000000000000000000000000000000;hb=0dcd2b11631fcf57602514e13fae9d31bbb79000;hp=438468464bdf832cd6725c65fb8d46f9034ca810;hpb=cb67a45f0e94c91583d7563f7a21d89845332c13;p=m6w6%2Fseekat diff --git a/lib/API/Deferred.php b/lib/API/Deferred.php deleted file mode 100644 index 4384684..0000000 --- a/lib/API/Deferred.php +++ /dev/null @@ -1,117 +0,0 @@ -api = $api; - $this->client = $client; - $this->request = $request; - - $client->attach($this); - $client->enqueue($request); - - parent::__construct(function($resolve, $reject) { - return $this->cancel($resolve, $reject); - }); - } - - /** - * Progress observer - * - * Import the response's data on success and resolve the promise. - * - * @var \SplSubject $client The observed HTTP client - * @var \http\Client\Request The request which generated the update - * @var object $progress The progress information - */ - function update(\SplSubject $client, Request $request = null, $progress = null) { - if ($request !== $this->request) { - return; - } - - $this->notify((object) compact("client", "request", "progress")); - - if ($progress->info === "finished") { - $this->response = $this->client->getResponse(); - $this->complete( - [$this, "resolve"], - [$this, "reject"] - ); - } - } - - /** - * Completion callback - * @param callable $resolve - * @param callable $reject - */ - private function complete(callable $resolve, callable $reject) { - $this->client->detach($this); - - if ($this->response) { - try { - $resolve($this->api->import($this->response)); - } catch (\Exception $e) { - $reject($e); - } - } else { - $reject($this->client->getTransferInfo($this->request)["error"]); - } - - $this->client->dequeue($this->request); - } - - /** - * Cancellation callback - * @param callable $resolve - * @param callable $reject - */ - private function cancel(callable $resolve, callable $reject) { - /* did we finish in the meantime? */ - if ($this->response) { - $this->complete($resolve, $reject); - } else { - $this->client->detach($this); - $this->client->dequeue($this->request); - $reject("Cancelled"); - } - } -}