Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Timer\timeout(…);

### timeout()

The `timeout(PromiseInterface<mixed, Exception|mixed> $promise, float $time, ?LoopInterface $loop = null): PromiseInterface<mixed, TimeoutException|Exception|mixed>` function can be used to
The `timeout(PromiseInterface<mixed, Throwable|mixed> $promise, float $time, ?LoopInterface $loop = null): PromiseInterface<mixed, TimeoutException|Throwable|mixed>` function can be used to
cancel operations that take *too long*.

You need to pass in an input `$promise` that represents a pending operation
Expand Down Expand Up @@ -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
Expand Down
24 changes: 10 additions & 14 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<mixed, \Exception|mixed> $promise
* @param PromiseInterface<mixed, \Throwable|mixed> $promise
* @param float $time
* @param ?LoopInterface $loop
* @return PromiseInterface<mixed, TimeoutException|\Exception|mixed>
* @return PromiseInterface<mixed, TimeoutException|\Throwable|mixed>
*/
function timeout(PromiseInterface $promise, $time, LoopInterface $loop = null)
{
Expand Down