Contents

mesqueeb/asyncify

```

Usage

Suppose you have a function that performs an asynchronous operation using a completion handler to deliver its result. You can use Asyncify to wrap this function and call it using Swift's async/await syntax.

Example:

// Example asynchronous function using a completion handler
func fetchUserDataWithHandler(completion: @escaping (Result<UserData, Error>) -> Void) {
    // ... your function implementation
}

// Set up an instance of Asyncify to use in the new async function
let asyncify = Asyncify<UserData>()

// Create a new async function using the `asyncify` instance
func fetchUserData() async throws -> UserData {
    try await asyncify.performOperation { completion in
        fetchUserDataWithHandler(completion: completion)
    }
}

// Usage
Task {
    do {
        let userData = try await fetchUserData()
        print("Fetched user data: \(userData)")
    } catch {
        print("Failed to fetch user data: \(error)")
    }
}

This example demonstrates how Asyncify can be used to adapt a traditional callback-based function (fetchUserData) into a modern async/await pattern (getUserDataAsync), making it easier to use within Swift's concurrency model.

Documentation

See the documentation for more info.

Package Metadata

Repository: mesqueeb/asyncify

Default branch: main

README: README.md