Skip to content

Commit

Permalink
Add EventLoopFuture.get() description (#1011)
Browse files Browse the repository at this point in the history
<!-- πŸš€ 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 <[email protected]>
Co-authored-by: Tim Condon <[email protected]>
  • Loading branch information
3 people authored Dec 1, 2024
1 parent a0c7fd2 commit 07ed13b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion docs/basics/async.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -315,7 +331,6 @@ print(string) /// String

!!! warning
Attempting to call `wait()` on an event loop thread will cause an assertion failure.


## Promise

Expand Down

0 comments on commit 07ed13b

Please sign in to comment.