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.
- Host: GitHub
- URL: https://github.com/cookednick/awaitreturn
- Owner: CookedNick
- License: mit
- Created: 2024-01-30T21:58:24.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-31T23:27:23.000Z (over 1 year ago)
- Last Synced: 2025-01-26T20:11:17.264Z (4 months ago)
- Language: Swift
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.