Skip to content

BridgeJS: Async function support #404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 17, 2025
Merged

BridgeJS: Async function support #404

merged 1 commit into from
Aug 17, 2025

Conversation

kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented Aug 13, 2025

This PR adds comprehensive async function support to BridgeJS, enabling seamless interoperability between Swift async functions and JavaScript Promises.
Swift functions marked with async are now automatically exposed as JavaScript functions returning Promise<T>

Implementation Details

Core Changes

  • ExportSwift.swift: Modified to detect async functions and wrap calls with JSPromise.async, handling proper return value conversion
  • BridgeJSLink.swift: Updated TypeScript signature generation to emit Promise<T> for async functions
  • TypeScript processor: Enhanced to recognize Promise types and generate appropriate bridge types

API Changes

  • Import initialization: Changed from imports: {...} to getImports() { return {...} } pattern to allow accessing exports inside imports implementation.

Example Usage

Swift side:

@JS func fetchUserData(_ userId: String) async -> String {
    // Async Swift implementation
    return userData
}

Generated JavaScript/TypeScript:

export type Exports = {
    fetchUserData(userId: string): Promise<string>;
}

This enhancement significantly improves the developer experience when working with async Swift code in JavaScript environments, providing type-safe Promise-based APIs that feel natural in both languages.

@kateinoigakukun kateinoigakukun linked an issue Aug 13, 2025 that may be closed by this pull request
@kateinoigakukun kateinoigakukun force-pushed the yt/bridgejs-async branch 3 times, most recently from bf5f4d9 to 139ea1c Compare August 17, 2025 02:52
Implements comprehensive async Swift-to-JavaScript interoperability using JSPromise.async wrapper.
Includes TypeScript Promise<T> type generation and full integration with module name architecture.
@kateinoigakukun kateinoigakukun marked this pull request as ready for review August 17, 2025 04:35
@kateinoigakukun kateinoigakukun merged commit 3176b60 into main Aug 17, 2025
9 checks passed
@kateinoigakukun kateinoigakukun deleted the yt/bridgejs-async branch August 17, 2025 05:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BridgeJS: Support exposing async functions
1 participant