sdk: Make the entire SDK API synchronous#720
Merged
Merged
Conversation
Replace the two conditional resolve_input implementations (async for non-CPP, sync for cpp-bindings) with a single synchronous version that wraps async internals via util::exec(). The entire public API exposed by the SDK through UniFFI is now synchronous. Functions that need async work (network I/O, gRPC) block the calling thread while an internal Tokio runtime executes the underlying operations. This gives every target language (Python, Kotlin, Swift, Ruby, C++) the same blocking API without requiring an async runtime or special feature flags on the caller side. - Remove `#[cfg(feature = "cpp-bindings")]` conditional compilation - Remove `#[uniffi::export(async_runtime = "tokio")]` attribute - Remove `cpp-bindings` feature from Cargo.toml - Drop uniffi `tokio` feature (no longer needed)
The cpp-bindings feature flag no longer exists; the standard build now produces a library that works for all bindings including C++.
Add a Synchronous API Design section to README.md explaining the rationale: uniform bindings across all languages, simpler caller-side integration, and no conditional compilation. Remove references to the now-deleted cpp-bindings feature from the C++ bindings instructions.
Document the resolve_input() synchronous switch and the removal of the cpp-bindings feature flag in the Unreleased section.
dde2459 to
d7f0c84
Compare
glsdk::resolve_input is now synchronous (blocks internally via util::exec). The NAPI binding was still .await-ing the Result, causing a compile error: error[E0277]: Result<ResolvedInput, Error> is not a future Wrap the call in tokio::task::spawn_blocking, consistent with every other blocking SDK call in the NAPI bindings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Make the entire public API exposed by
gl-sdkthrough UniFFI synchronous. Functions that need async work (LNURL HTTP fetches, gRPC calls) block the calling thread while an internal Tokio runtime executes the underlying operations.This removes the hacky
#[cfg(feature = "cpp-bindings")]conditional compilation that was introduced in #718 to work arounduniffi-bindgen-cppnot supporting async exports. Instead of maintaining two implementations ofresolve_input(async for non-CPP, sync for CPP), there is now a single synchronous version that works for all bindings.Rationale
threadingin Python,std::threadin C++, coroutines in Kotlin).Changes
lib.rs: Replace dual conditionalresolve_inputwith a single sync version usingutil::exec()Cargo.toml: Removecpp-bindingsfeature flag anduniffitokio feature.tasks.yml: Remove--features cpp-bindingsfrombindings-cpptaskREADME.md: Add "Synchronous API Design" section documenting the rationale; remove feature flag references from C++ instructionsCHANGELOG.md: Document changes in Unreleased sectionTesting
All 19 unit tests pass (
cargo test -p gl-sdk).