basic async-interop support; generator consumer missing
[m6w6/seekat] / lib / API / Call.php
index f10d6e81328f79373f168fe9e41616129b22d95e..ba51ca3fe23dbe2d74ef60a2b3bc9afe6974bf00 100644 (file)
@@ -2,8 +2,8 @@
 
 namespace seekat\API;
 
+use AsyncInterop\Promise;
 use http\Url;
-use React\Promise\ExtendedPromiseInterface;
 use seekat\API;
 use seekat\Exception;
 
@@ -24,12 +24,15 @@ final class Call
                $this->call = $call;
        }
 
-       function __invoke(array $args) : ExtendedPromiseInterface {
+       function __invoke(array $args) : Promise {
                $promise = $this->api->{$this->call}->get(...$args);
 
                /* fetch resource, unless already localized, and try for {$method}_url */
                if (!$this->api->exists($this->call)) {
-                       $promise = $promise->otherwise(function($error) use($args) {
+                       $promise->when(function($error, $value) use($args) {
+                               if (!isset($error)) {
+                                       return $value;
+                               }
                                if ($this->api->exists($this->call."_url", $url)) {
                                        $url = new Url(uri_template($url, (array)current($args)));
                                        return $this->api->withUrl($url)->get(...$args);