Skip to content

Commit

Permalink
Use shorthand instead of Runnable in CatalystInstanceImpl (#39972)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #39972

Using shorthand expression instead of `Runnable` in CatalystInstanceImpl

Changelog:
[Internal] internal

Reviewed By: christophpurrer

Differential Revision: D50039800

fbshipit-source-id: cf1fff19302302e9a5c4fe1db2b6ad613abb48b6
  • Loading branch information
arushikesarwani94 authored and facebook-github-bot committed Oct 9, 2023
1 parent 29dce4d commit ec1de61
Showing 1 changed file with 54 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,66 +346,53 @@ public void destroy() {
mDestroyed = true;

mNativeModulesQueueThread.runOnQueue(
new Runnable() {
@Override
public void run() {
mNativeModuleRegistry.notifyJSInstanceDestroy();
mJSIModuleRegistry.notifyJSInstanceDestroy();
boolean wasIdle = (mPendingJSCalls.getAndSet(0) == 0);
if (!mBridgeIdleListeners.isEmpty()) {
for (NotThreadSafeBridgeIdleDebugListener listener : mBridgeIdleListeners) {
if (!wasIdle) {
listener.onTransitionToBridgeIdle();
}
listener.onBridgeDestroyed();
() -> {
mNativeModuleRegistry.notifyJSInstanceDestroy();
mJSIModuleRegistry.notifyJSInstanceDestroy();
boolean wasIdle = (mPendingJSCalls.getAndSet(0) == 0);
if (!mBridgeIdleListeners.isEmpty()) {
for (NotThreadSafeBridgeIdleDebugListener listener : mBridgeIdleListeners) {
if (!wasIdle) {
listener.onTransitionToBridgeIdle();
}
listener.onBridgeDestroyed();
}

getReactQueueConfiguration()
.getJSQueueThread()
.runOnQueue(
new Runnable() {
@Override
public void run() {
// We need to destroy the TurboModuleManager on the JS Thread
if (mTurboModuleRegistry != null) {
mTurboModuleRegistry.invalidate();
}

getReactQueueConfiguration()
.getUIQueueThread()
.runOnQueue(
new Runnable() {
@Override
public void run() {
// AsyncTask.execute must be executed from the UI Thread
AsyncTask.execute(
new Runnable() {
@Override
public void run() {
// Kill non-UI threads from neutral third party
// potentially expensive, so don't run on UI thread

// contextHolder is used as a lock to guard against
// other users of the JS VM having the VM destroyed
// underneath them, so notify them before we reset
// Native
mJavaScriptContextHolder.clear();

mHybridData.resetNative();
getReactQueueConfiguration().destroy();
FLog.d(
ReactConstants.TAG,
"CatalystInstanceImpl.destroy() end");
ReactMarker.logMarker(
ReactMarkerConstants.DESTROY_CATALYST_INSTANCE_END);
}
});
}
});
}
});
}

getReactQueueConfiguration()
.getJSQueueThread()
.runOnQueue(
() -> {
// We need to destroy the TurboModuleManager on the JS Thread
if (mTurboModuleRegistry != null) {
mTurboModuleRegistry.invalidate();
}

getReactQueueConfiguration()
.getUIQueueThread()
.runOnQueue(
() -> {
// AsyncTask.execute must be executed from the UI Thread
AsyncTask.execute(
() -> {
// Kill non-UI threads from neutral third party
// potentially expensive, so don't run on UI thread

// contextHolder is used as a lock to guard against
// other users of the JS VM having the VM destroyed
// underneath them, so notify them before we reset
// Native
mJavaScriptContextHolder.clear();

mHybridData.resetNative();
getReactQueueConfiguration().destroy();
FLog.d(
ReactConstants.TAG, "CatalystInstanceImpl.destroy() end");
ReactMarker.logMarker(
ReactMarkerConstants.DESTROY_CATALYST_INSTANCE_END);
});
});
});
});

// This is a noop if the listener was not yet registered.
Expand All @@ -430,11 +417,8 @@ public void initialize() {
Assertions.assertCondition(mAcceptCalls, "RunJSBundle hasn't completed.");
mInitialized = true;
mNativeModulesQueueThread.runOnQueue(
new Runnable() {
@Override
public void run() {
mNativeModuleRegistry.notifyJSInstanceInitialized();
}
() -> {
mNativeModuleRegistry.notifyJSInstanceInitialized();
});
}

Expand Down Expand Up @@ -572,12 +556,9 @@ private void incrementPendingJSCalls() {
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, mJsPendingCallsTitleForTrace, oldPendingCalls + 1);
if (wasIdle && !mBridgeIdleListeners.isEmpty()) {
mNativeModulesQueueThread.runOnQueue(
new Runnable() {
@Override
public void run() {
for (NotThreadSafeBridgeIdleDebugListener listener : mBridgeIdleListeners) {
listener.onTransitionToBridgeBusy();
}
() -> {
for (NotThreadSafeBridgeIdleDebugListener listener : mBridgeIdleListeners) {
listener.onTransitionToBridgeBusy();
}
});
}
Expand All @@ -597,12 +578,9 @@ private void decrementPendingJSCalls() {

if (isNowIdle && !mBridgeIdleListeners.isEmpty()) {
mNativeModulesQueueThread.runOnQueue(
new Runnable() {
@Override
public void run() {
for (NotThreadSafeBridgeIdleDebugListener listener : mBridgeIdleListeners) {
listener.onTransitionToBridgeIdle();
}
() -> {
for (NotThreadSafeBridgeIdleDebugListener listener : mBridgeIdleListeners) {
listener.onTransitionToBridgeIdle();
}
});
}
Expand All @@ -613,11 +591,8 @@ private void onNativeException(Exception e) {
mReactQueueConfiguration
.getUIQueueThread()
.runOnQueue(
new Runnable() {
@Override
public void run() {
destroy();
}
() -> {
destroy();
});
}

Expand Down

0 comments on commit ec1de61

Please sign in to comment.