Add EventLoopFuture.get() description (#1011)

<!-- 🚀 Thank you for contributing! -->

<!-- Describe your changes clearly and use examples if possible. -->

Add EventLoopFuture.get() description:

    try await EventLoopFuture.get()

<!-- When this PR is merged, the title and body will be -->
<!-- used to generate a release automatically. -->

---------

Co-authored-by: Przemysław Wrzesiński <p.wrzesinski@vatio.eu>
Co-authored-by: Tim Condon <0xTim@users.noreply.github.com>
This commit is contained in:
Przemysław Wrzesiński 2024-12-01 15:02:35 +01:00 committed by GitHub
parent a0c7fd2137
commit 07ed13b42b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 1 deletions

View File

@ -297,9 +297,25 @@ futureString.whenComplete { result in
!!! note
You can add as many callbacks to a future as you want.
### Get
In case there is no concurrency-based alternative to an API, you can await for the future's value using `try await future.get()`.
```swift
/// Assume we get a future string back from some API
let futureString: EventLoopFuture<String> = ...
/// Wait for the string to be ready
let string: String = try await futureString.get()
print(string) /// String
```
### Wait
!!! warning
The `wait()` function is obsolete, see [`Get`](#get) for the recommended approach.
You can use `.wait()` to synchronously wait for the future to be completed. Since a future may fail, this call is throwing.
```swift
@ -315,7 +331,6 @@ print(string) /// String
!!! warning
Attempting to call `wait()` on an event loop thread will cause an assertion failure.
## Promise