Skip to content

Commit 3767380

Browse files
authored
Update README.md
1 parent 3064fff commit 3767380

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@ let val = try await withThrowingTimeout(seconds: 2.0) {
4040

4141
> Note: When the timeout expires the task executing the closure is cancelled and `TimeoutError` is thrown.
4242
43+
An overload includes the `Timeout` object that allows the body to cancel or move the expiration if required:
44+
45+
```swift
46+
try await withThrowingTimeout(seconds: 1.0) { timeout in
47+
try await foo()
48+
timeout.cancelExpiration()
49+
try await bar()
50+
timeout.expire(afer: 0.5)
51+
try await baz()
52+
}
53+
```
54+
55+
`AsyncTimeoutSequence` allows each iteration a fresh timeout to return the next element;
56+
57+
```swift
58+
for try await val in sequence.timeout(seconds: 2.0) {
59+
...
60+
}
61+
```
62+
4363
# Credits
4464

4565
Timeout is primarily the work of [Simon Whitty](https://github.com/swhitty).

0 commit comments

Comments
 (0)