Skip to content

Commit 087d876

Browse files
authored
Merge pull request #58 from clue-labs/promise-docs
Minor documentation improvements for upcoming Promise v3
2 parents 00faadc + 23a5416 commit 087d876

File tree

2 files changed

+19
-27
lines changed

2 files changed

+19
-27
lines changed

README.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Timer\timeout(…);
4747

4848
### timeout()
4949

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

5353
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(
104104
);
105105
```
106106

107-
Or if you're using [react/promise v2.2.0](https://github.com/reactphp/promise) or up:
107+
Or if you're using [react/promise v3](https://github.com/reactphp/promise):
108108

109109
```php
110-
React\Promise\Timer\timeout($promise, 10.0)
111-
->then(function ($value) {
112-
// the operation finished within 10.0 seconds
113-
})
114-
->otherwise(function (React\Promise\Timer\TimeoutException $error) {
115-
// the operation has failed due to a timeout
116-
})
117-
->otherwise(function ($error) {
118-
// the input operation has failed due to some other error
119-
})
120-
;
110+
React\Promise\Timer\timeout($promise, 10.0)->then(function ($value) {
111+
// the operation finished within 10.0 seconds
112+
})->catch(function (React\Promise\Timer\TimeoutException $error) {
113+
// the operation has failed due to a timeout
114+
})->catch(function (Throwable $error) {
115+
// the input operation has failed due to some other error
116+
});
121117
```
122118

123119
As discussed above, the [`timeout()`](#timeout) function will take care of

src/functions.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,16 @@
6464
* );
6565
* ```
6666
*
67-
* Or if you're using [react/promise v2.2.0](https://github.com/reactphp/promise) or up:
67+
* Or if you're using [react/promise v3](https://github.com/reactphp/promise):
6868
*
6969
* ```php
70-
* React\Promise\Timer\timeout($promise, 10.0)
71-
* ->then(function ($value) {
72-
* // the operation finished within 10.0 seconds
73-
* })
74-
* ->otherwise(function (React\Promise\Timer\TimeoutException $error) {
75-
* // the operation has failed due to a timeout
76-
* })
77-
* ->otherwise(function ($error) {
78-
* // the input operation has failed due to some other error
79-
* })
80-
* ;
70+
* React\Promise\Timer\timeout($promise, 10.0)->then(function ($value) {
71+
* // the operation finished within 10.0 seconds
72+
* })->catch(function (React\Promise\Timer\TimeoutException $error) {
73+
* // the operation has failed due to a timeout
74+
* })->catch(function (Throwable $error) {
75+
* // the input operation has failed due to some other error
76+
* });
8177
* ```
8278
*
8379
* As discussed above, the [`timeout()`](#timeout) function will take care of
@@ -133,10 +129,10 @@
133129
* For more details on the promise primitives, please refer to the
134130
* [Promise documentation](https://github.com/reactphp/promise#functions).
135131
*
136-
* @param PromiseInterface<mixed, \Exception|mixed> $promise
132+
* @param PromiseInterface<mixed, \Throwable|mixed> $promise
137133
* @param float $time
138134
* @param ?LoopInterface $loop
139-
* @return PromiseInterface<mixed, TimeoutException|\Exception|mixed>
135+
* @return PromiseInterface<mixed, TimeoutException|\Throwable|mixed>
140136
*/
141137
function timeout(PromiseInterface $promise, $time, LoopInterface $loop = null)
142138
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy