An open API service indexing awesome lists of open source software.

https://github.com/cookednick/awaitreturn

(Swift) Return values from asynchronous contexts into concurrent ones.
https://github.com/cookednick/awaitreturn

Last synced: 2 months ago
JSON representation

(Swift) Return values from asynchronous contexts into concurrent ones.

Awesome Lists containing this project

README

        

Sometimes, within a concurrent context, you need data that is only accessible via asynchronous code. For example, actors work by requiring `await` statements before their data can be accessed.
There is no easy one-line way to do this in Swift as of Swift 5.9.2. **AwaitReturn is one easy way to do this.**

## Usage

```swift
func getName() {
// Within the awaitReturn block, you can write async code and return it normally.
let name = awaitReturn { await someActor.name }
// We now have a "name" constant of type String in our concurrent context.
print(name)
}
```

## Installation

Include `AwaitReturn.swift` in your project. That's it.