Skip to content

Commit

Permalink
Quick and dirty async invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Salinas authored and Daniel Salinas committed Sep 12, 2024
1 parent 9bae622 commit bc3371a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 7 additions & 0 deletions cpp/includes/UniffiCallInvoker.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,12 @@ class UniffiCallInvoker {
cv.wait(lock, [&done] { return done; });
}
}

void invokeAsync(jsi::Runtime &rt, UniffiCallFunc &func) {
std::function<void()> wrapper = [&func, &rt]() {
func(rt);
};
callInvoker_->invokeAsync(std::move(wrapper));
}
};
} // namespace uniffi_runtime
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ namespace {{ ns }} {
makeCallbackFunction( // {{ ns }}
jsi::Runtime &rt,
std::shared_ptr<uniffi_runtime::UniffiCallInvoker> callInvoker,
const jsi::Value &value) {
const jsi::Value &value,
bool invokeAsync = false) {
auto callbackFunction = value.asObject(rt).asFunction(rt);
auto callbackValue = std::make_shared<jsi::Value>(rt, callbackFunction);
rsLambda = [&rt, callInvoker, callbackValue](
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ template <> struct Bridging<UniffiRustFutureContinuationCallback> {
static auto callback = {{ cb_type.borrow()|cpp_namespace(ci) }}::makeCallbackFunction(
rt,
callInvoker,
value
value,
true
);
return callback;
} catch (const std::logic_error &e) {
Expand Down

0 comments on commit bc3371a

Please sign in to comment.