File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,26 @@ let val = try await withThrowingTimeout(seconds: 2.0) {
40
40
41
41
> Note: When the timeout expires the task executing the closure is cancelled and ` TimeoutError ` is thrown.
42
42
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
+
43
63
# Credits
44
64
45
65
Timeout is primarily the work of [ Simon Whitty] ( https://github.com/swhitty ) .
You can’t perform that action at this time.
0 commit comments