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) {
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
4565Timeout is primarily the work of [ Simon Whitty] ( https://github.com/swhitty ) .
You can’t perform that action at this time.
0 commit comments