Skip to content

mbentin/CombineCompatibilityMacro

Repository files navigation

Combine compability macro

This swift macro synthetizes the combine calls from async await calls.

Protocols

Define the protocol with the annotation

@ProtocolCombineCompatibility
protocol MyP {
    func foobar() async throws -> String
}

Implement the async call.

struct My : MyP {
    func foobar() async throws -> String {
        await withCheckedContinuation { body in
            body.resume(returning: "Async call")
        }
    }
}

Get the Combine call with Future automatically

let my = My()
print(try await my.foobar())
let _ = my.foobar()
    .sink(
        receiveCompletion: { print("Combine: \($0)") },
        receiveValue: { print("Combine: \($0)") }
    )

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published