Skip to content
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

feat: Implement callbacks that return a value in Swift/Kotlin 🥳 #417

Merged
merged 6 commits into from
Dec 10, 2024

Conversation

mrousavy
Copy link
Owner

@mrousavy mrousavy commented Dec 10, 2024

This now works:

interface SomeHybrid extends HybridObject<{ }> {
  // Callbacks that return values
  getValueFromJSCallbackAndWait(getValue: () => number): Promise<number>
  getValueFromJsCallback(
    callback: () => string,
    andThenCall: (valueFromJs: string) => void
  ): Promise<void>
}

..in Swift and Kotlin:

func getValueFromJSCallbackAndWait(getValue: @escaping (() -> Promise<Double>)) throws -> Promise<Double> {
  return .async {
    let jsResult = try await getValue().await()
    return jsResult
  }
}

func getValueFromJsCallback(callback: @escaping (() -> Promise<String>),
                            andThenCall: @escaping ((_ valueFromJs: String) -> Void)) throws -> Promise<Void> {
  return .async {
    let jsResult = try await callback().await()
    andThenCall(jsResult)
  }
}

..and the tests for it.

Copy link

vercel bot commented Dec 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
nitro-docs ⬜️ Skipped (Inspect) Dec 10, 2024 3:27pm

@mrousavy mrousavy merged commit 4b54687 into main Dec 10, 2024
16 checks passed
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.

1 participant