Skip to content

Commit

Permalink
lift isSyncModule_ check outside of isMethodSync
Browse files Browse the repository at this point in the history
Summary:
Changelog: [Internal]

some cleanup!

Differential Revision: D49521863

fbshipit-source-id: 9a31b2ae48069f3b8722b99889db0b8695b4f40d
  • Loading branch information
philIip authored and facebook-github-bot committed Sep 21, 2023
1 parent 0da5641 commit 0892e98
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s

bool ObjCTurboModule::isMethodSync(TurboModuleMethodValueKind returnType)
{
return isSyncModule_ || !(returnType == VoidKind || returnType == PromiseKind);
return !(returnType == VoidKind || returnType == PromiseKind);
}

ObjCTurboModule::ObjCTurboModule(const InitParams &params)
Expand All @@ -703,15 +703,17 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s
const char *moduleName = name_.c_str();
const char *methodName = methodNameStr.c_str();

if (isMethodSync(returnType)) {
bool isSyncInvocation = isSyncModule_ || isMethodSync(returnType);

if (isSyncInvocation) {
TurboModulePerfLogger::syncMethodCallStart(moduleName, methodName);
} else {
TurboModulePerfLogger::asyncMethodCallStart(moduleName, methodName);
}

NSMutableArray *retainedObjectsForInvocation = [NSMutableArray arrayWithCapacity:count + 2];
NSInvocation *inv = createMethodInvocation(
runtime, isMethodSync(returnType), methodName, selector, args, count, retainedObjectsForInvocation);
runtime, isSyncInvocation, methodName, selector, args, count, retainedObjectsForInvocation);

jsi::Value returnValue = jsi::Value::undefined();

Expand All @@ -726,24 +728,24 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s
[retainedObjectsForInvocation addObject:resolveCopy];
[retainedObjectsForInvocation addObject:rejectCopy];
// The return type becomes void in the ObjC side.
performMethodInvocation(runtime, isMethodSync(VoidKind), methodName, inv, retainedObjectsForInvocation);
performMethodInvocation(runtime, isSyncInvocation, methodName, inv, retainedObjectsForInvocation);
});
} else {
id result =
performMethodInvocation(runtime, isMethodSync(returnType), methodName, inv, retainedObjectsForInvocation);
performMethodInvocation(runtime, isSyncInvocation, methodName, inv, retainedObjectsForInvocation);

if (isMethodSync(returnType)) {
if (isSyncInvocation) {
TurboModulePerfLogger::syncMethodCallReturnConversionStart(moduleName, methodName);
}

returnValue = convertReturnIdToJSIValue(runtime, methodName, returnType, result);

if (isMethodSync(returnType)) {
if (isSyncInvocation) {
TurboModulePerfLogger::syncMethodCallReturnConversionEnd(moduleName, methodName);
}
}

if (isMethodSync(returnType)) {
if (isSyncInvocation) {
TurboModulePerfLogger::syncMethodCallEnd(moduleName, methodName);
} else {
TurboModulePerfLogger::asyncMethodCallEnd(moduleName, methodName);
Expand Down

0 comments on commit 0892e98

Please sign in to comment.