You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+185Lines changed: 185 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,185 @@ A trivial implementation of timeouts for `Promise`s, built on top of [React PHP]
4
4
5
5
> Note: This project is in early alpha stage! Feel free to report any issues you encounter.
6
6
7
+
## Usage
8
+
9
+
This lightweight library consists only of a few simple functions.
10
+
All functions reside under the `Clue\Promise\Timer` namespace.
11
+
12
+
The below examples assume you use an import statement similar to this:
13
+
14
+
```php
15
+
use Clue\Promise\Timer;
16
+
17
+
Timer\timeout(…);
18
+
```
19
+
20
+
Alternatively, you can also refer to them with their fully-qualified name:
21
+
22
+
```php
23
+
\Clue\Promise\Timer\timeout(…);
24
+
```
25
+
26
+
### timeout()
27
+
28
+
The `timeout(PromiseInterface $promise, $time, LoopInterface $loop)` function
29
+
can be used to *cancel* operations that take *too long*.
30
+
You need to pass in an input `$promise` that represents a pending operation and timeout parameters.
31
+
It returns a new `Promise` with the following resolution behavior:
32
+
33
+
* If the input `$promise` resolves before `$time` seconds, resolve the resulting promise with its fulfillment value.
34
+
* If the input `$promise` rejects before `$time` seconds, reject the resulting promise with its rejection value.
35
+
* If the input `$promise` does not settle before `$time` seconds, *cancel* the operation and reject the resulting promise with a [`TimeoutException`](#timeoutexception).
36
+
37
+
A common use case for handling only resolved values looks like this:
0 commit comments