diff --git a/README.md b/README.md index 90c4680..dc09f24 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Timer\timeout(…); ### timeout() -The `timeout(PromiseInterface $promise, float $time, ?LoopInterface $loop = null): PromiseInterface` function can be used to +The `timeout(PromiseInterface $promise, float $time, ?LoopInterface $loop = null): PromiseInterface` function can be used to cancel operations that take *too long*. You need to pass in an input `$promise` that represents a pending operation @@ -104,20 +104,16 @@ React\Promise\Timer\timeout($promise, 10.0)->then( ); ``` -Or if you're using [react/promise v2.2.0](https://github.com/reactphp/promise) or up: +Or if you're using [react/promise v3](https://github.com/reactphp/promise): ```php -React\Promise\Timer\timeout($promise, 10.0) - ->then(function ($value) { - // the operation finished within 10.0 seconds - }) - ->otherwise(function (React\Promise\Timer\TimeoutException $error) { - // the operation has failed due to a timeout - }) - ->otherwise(function ($error) { - // the input operation has failed due to some other error - }) -; +React\Promise\Timer\timeout($promise, 10.0)->then(function ($value) { + // the operation finished within 10.0 seconds +})->catch(function (React\Promise\Timer\TimeoutException $error) { + // the operation has failed due to a timeout +})->catch(function (Throwable $error) { + // the input operation has failed due to some other error +}); ``` As discussed above, the [`timeout()`](#timeout) function will take care of diff --git a/src/functions.php b/src/functions.php index a8b1fd5..b72bf36 100644 --- a/src/functions.php +++ b/src/functions.php @@ -64,20 +64,16 @@ * ); * ``` * - * Or if you're using [react/promise v2.2.0](https://github.com/reactphp/promise) or up: + * Or if you're using [react/promise v3](https://github.com/reactphp/promise): * * ```php - * React\Promise\Timer\timeout($promise, 10.0) - * ->then(function ($value) { - * // the operation finished within 10.0 seconds - * }) - * ->otherwise(function (React\Promise\Timer\TimeoutException $error) { - * // the operation has failed due to a timeout - * }) - * ->otherwise(function ($error) { - * // the input operation has failed due to some other error - * }) - * ; + * React\Promise\Timer\timeout($promise, 10.0)->then(function ($value) { + * // the operation finished within 10.0 seconds + * })->catch(function (React\Promise\Timer\TimeoutException $error) { + * // the operation has failed due to a timeout + * })->catch(function (Throwable $error) { + * // the input operation has failed due to some other error + * }); * ``` * * As discussed above, the [`timeout()`](#timeout) function will take care of @@ -133,10 +129,10 @@ * For more details on the promise primitives, please refer to the * [Promise documentation](https://github.com/reactphp/promise#functions). * - * @param PromiseInterface $promise + * @param PromiseInterface $promise * @param float $time * @param ?LoopInterface $loop - * @return PromiseInterface + * @return PromiseInterface */ function timeout(PromiseInterface $promise, $time, LoopInterface $loop = null) {