diff --git a/cpp/includes/UniffiCallInvoker.h b/cpp/includes/UniffiCallInvoker.h index 90ddd424..5b3db3e2 100644 --- a/cpp/includes/UniffiCallInvoker.h +++ b/cpp/includes/UniffiCallInvoker.h @@ -80,5 +80,12 @@ class UniffiCallInvoker { cv.wait(lock, [&done] { return done; }); } } + + void invokeAsync(jsi::Runtime &rt, UniffiCallFunc &func) { + std::function wrapper = [&func, &rt]() { + func(rt); + }; + callInvoker_->invokeAsync(std::move(wrapper)); + } }; } // namespace uniffi_runtime diff --git a/crates/ubrn_bindgen/src/bindings/react_native/gen_cpp/templates/CallbackFunction.cpp b/crates/ubrn_bindgen/src/bindings/react_native/gen_cpp/templates/CallbackFunction.cpp index 20aadbd2..90f37a42 100644 --- a/crates/ubrn_bindgen/src/bindings/react_native/gen_cpp/templates/CallbackFunction.cpp +++ b/crates/ubrn_bindgen/src/bindings/react_native/gen_cpp/templates/CallbackFunction.cpp @@ -148,7 +148,8 @@ namespace {{ ns }} { makeCallbackFunction( // {{ ns }} jsi::Runtime &rt, std::shared_ptr callInvoker, - const jsi::Value &value) { + const jsi::Value &value, + bool invokeAsync = false) { auto callbackFunction = value.asObject(rt).asFunction(rt); auto callbackValue = std::make_shared(rt, callbackFunction); rsLambda = [&rt, callInvoker, callbackValue]( @@ -187,7 +188,11 @@ namespace {{ ns }} { }; // We'll then call that lambda from the callInvoker which will // look after calling it on the correct thread. - callInvoker->invokeBlocking(rt, jsLambda); + if (invokeAsync) { + callInvoker->invokeAsync(rt, jsLambda); + } else { + callInvoker->invokeBlocking(rt, jsLambda); + } }; return callback; } diff --git a/crates/ubrn_bindgen/src/bindings/react_native/gen_cpp/templates/Future.cpp b/crates/ubrn_bindgen/src/bindings/react_native/gen_cpp/templates/Future.cpp index a7de0135..5980f643 100644 --- a/crates/ubrn_bindgen/src/bindings/react_native/gen_cpp/templates/Future.cpp +++ b/crates/ubrn_bindgen/src/bindings/react_native/gen_cpp/templates/Future.cpp @@ -14,7 +14,8 @@ template <> struct Bridging { static auto callback = {{ cb_type.borrow()|cpp_namespace(ci) }}::makeCallbackFunction( rt, callInvoker, - value + value, + true ); return callback; } catch (const std::logic_error &e) {