mirror of https://github.com/vapor/docs.git
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:
parent
a0c7fd2137
commit
07ed13b42b
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue