C++ Turbo Module > Allow Promise<void> types (#52388)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/52388

Changelog: [Internal]

Similar to `AsyncCallback<>` (the foundation of `AsyncPromise`) we should allow `void` Promise types in C++ such as `AsyncPromise<>`

Reviewed By: rbergerjr

Differential Revision: D77712020

fbshipit-source-id: d7360df5cc1b77f1e03e5fb73b0b468f6e3a415b
This commit is contained in:
Christoph Purrer
2025-07-06 19:53:51 -07:00
committed by Facebook GitHub Bot
parent 255977a7b9
commit e8709355dc
5 changed files with 33 additions and 15 deletions
@@ -177,6 +177,12 @@ void NativeCxxModuleExample::voidFunc(jsi::Runtime& rt) {
emitOnEvent(NativeCxxModuleExampleEnumNone::NA);
}
AsyncPromise<> NativeCxxModuleExample::voidPromise(jsi::Runtime& rt) {
AsyncPromise<> promise(rt, jsInvoker_);
promise.resolve();
return promise;
}
void NativeCxxModuleExample::setMenu(jsi::Runtime& rt, MenuItem menuItem) {
menuItem.onPress("value", true);
if (menuItem.items) {
@@ -213,8 +219,7 @@ ObjectStruct NativeCxxModuleExample::getObjectThrows(
throw std::runtime_error("Intentional exception from Cxx getObjectThrows");
};
AsyncPromise<jsi::Value> NativeCxxModuleExample::promiseThrows(
jsi::Runtime& rt) {
AsyncPromise<> NativeCxxModuleExample::promiseThrows(jsi::Runtime& rt) {
throw std::runtime_error("Intentional exception from Cxx promiseThrows");
};
@@ -231,12 +236,11 @@ ObjectStruct NativeCxxModuleExample::getObjectAssert(
return {};
};
AsyncPromise<jsi::Value> NativeCxxModuleExample::promiseAssert(
jsi::Runtime& rt) {
AsyncPromise<> NativeCxxModuleExample::promiseAssert(jsi::Runtime& rt) {
react_native_assert(false && "Intentional assert from Cxx promiseAssert");
// Asserts disabled
auto promise = AsyncPromise<jsi::Value>(rt, jsInvoker_);
auto promise = AsyncPromise<>(rt, jsInvoker_);
promise.reject("Asserts disabled");
return promise;
};