- function __invoke() : Promise {
- if ($this->cache->load($this->request, $cached)) {
- $this->logger->info("deferred -> cached", [
- "method" => $this->request->getRequestMethod(),
- "url" => $this->request->getRequestUrl(),
- ]);
-
- $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;
- } else {
- $this->response = $response;
- }
- $this->complete();
- return true;
- });
- $this->logger->info("deferred -> enqueued", [
- "method" => $this->request->getRequestMethod(),
- "url" => $this->request->getRequestUrl(),
- ]);
- /* start off */
- $this->client->once();