Skip to content

Conversation

Choochmeque
Copy link

This adds support for invoking plugin methods that Swift exposes as async / async throws.
In the Objective-C runtime, such methods are automatically bridged into selectors with a completionHandler: parameter (e.g. commandName:completionHandler:).
• Detects and invokes completionHandler: selectors with a block that rejects if an error is passed.
• Falls back to the existing error: selector for throwing methods.
• No breaking changes — plugins can now use either throws or async/await Swift APIs.

Code example:

    @objc public func getProducts(_ invoke: Invoke) async throws {
        let args = try invoke.parseArgs(GetProductsArgs.self)
        
        do {
            let products = try await Product.products(for: args.productIds)
            var productsArray: [[String: Any]] = []
            
            // Other code

            invoke.resolve(["products": productsArray])
        } catch {
            invoke.reject("Failed to fetch products: \(error.localizedDescription)")
        }
    }	

Without this change, async Swift plugin methods cannot be called and result is "No command getProducts found for plugin"

@Choochmeque Choochmeque requested a review from a team as a code owner September 4, 2025 09:58
@github-project-automation github-project-automation bot moved this to 📬Proposal in Roadmap Sep 4, 2025
@Choochmeque
Copy link
Author

@FabianLars, could you please review this PR?

@FabianLars
Copy link
Member

I'm out of office for the next 2-3 so no promises that I can squeeze it in in that timeframe.

@Choochmeque
Copy link
Author

@FabianLars No worries at all.
I have a workaround in place for now:

    @objc public func getProducts(_ invoke: Invoke) throws {
        Task {
            try await self.getProducts(invoke)
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📬Proposal
Development

Successfully merging this pull request may close these issues.

2 participants