From 9adb094a7570561fba3e14081cba2649c6fa6785 Mon Sep 17 00:00:00 2001
From: Parsa Nasirimehr
Date: Mon, 13 Jan 2025 20:53:42 +0100
Subject: [PATCH] chore: migrate MessageQueueThread
---
.../react/bridge/queue/MessageQueueThread.kt | 108 ++++++++----------
.../bridge/queue/MessageQueueThreadImpl.kt | 12 +-
2 files changed, 53 insertions(+), 67 deletions(-)
diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/queue/MessageQueueThread.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/queue/MessageQueueThread.kt
index 17479a2a4f386b..7300a1af56e716 100644
--- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/queue/MessageQueueThread.kt
+++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/queue/MessageQueueThread.kt
@@ -4,77 +4,63 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
+package com.facebook.react.bridge.queue
-package com.facebook.react.bridge.queue;
+import com.facebook.proguard.annotations.DoNotStrip
+import com.facebook.react.bridge.AssertionException
+import java.util.concurrent.Callable
+import java.util.concurrent.Future
-import androidx.annotation.Nullable;
-import com.facebook.proguard.annotations.DoNotStrip;
-import com.facebook.react.bridge.AssertionException;
-
-import java.util.concurrent.Callable;
-import java.util.concurrent.Future;
-
-/** Encapsulates a Thread that can accept Runnables. */
+/** Encapsulates a Thread that can accept Runnables. */
@DoNotStrip
public interface MessageQueueThread {
- /**
- * Runs the given Runnable on this Thread. It will be submitted to the end of the event queue even
- * if it is being submitted from the same queue Thread.
- */
- @DoNotStrip
- boolean runOnQueue(Runnable runnable);
+ /**
+ * Runs the given Runnable on this Thread. It will be submitted to the end of the event queue even
+ * if it is being submitted from the same queue Thread.
+ */
+ @DoNotStrip
+ public fun runOnQueue(runnable: Runnable): Boolean
- /**
- * Runs the given Callable on this Thread. It will be submitted to the end of the event queue even
- * if it is being submitted from the same queue Thread.
- */
- @DoNotStrip
- Future callOnQueue(final Callable callable);
+ /**
+ * Runs the given Callable on this Thread. It will be submitted to the end of the event queue even
+ * if it is being submitted from the same queue Thread.
+ */
+ @DoNotStrip
+ public fun callOnQueue(callable: Callable): Future
- /**
- * @return whether the current Thread is also the Thread associated with this MessageQueueThread.
- */
- @DoNotStrip
- boolean isOnThread();
+ @DoNotStrip
+ public fun isOnThread(): Boolean
- /**
- * Asserts {@link #isOnThread()}, throwing a {@link AssertionException} (NOT an {@link
- * AssertionError}) if the assertion fails.
- */
- @DoNotStrip
- void assertIsOnThread();
+ /**
+ * Asserts [.isOnThread], throwing a [AssertionException] (NOT an [ ]) if the assertion fails.
+ */
+ @DoNotStrip
+ public fun assertIsOnThread()
- /**
- * Asserts {@link #isOnThread()}, throwing a {@link AssertionException} (NOT an {@link
- * AssertionError}) if the assertion fails. The given message is appended to the error.
- */
- @DoNotStrip
- void assertIsOnThread(String message);
+ /**
+ * Asserts [.isOnThread], throwing a [AssertionException] (NOT an [ ]) if the assertion fails. The given message is appended to the error.
+ */
+ @DoNotStrip
+ public fun assertIsOnThread(message: String)
- /**
- * Quits this MessageQueueThread. If called from this MessageQueueThread, this will be the last
- * thing the thread runs. If called from a separate thread, this will block until the thread can
- * be quit and joined.
- */
- @DoNotStrip
- void quitSynchronous();
+ /**
+ * Quits this MessageQueueThread. If called from this MessageQueueThread, this will be the last
+ * thing the thread runs. If called from a separate thread, this will block until the thread can
+ * be quit and joined.
+ */
+ @DoNotStrip
+ public fun quitSynchronous()
- /**
- * Returns the perf counters taken when the framework was started. This method is intended to be
- * used for instrumentation purposes.
- */
- @Nullable
- @DoNotStrip
- MessageQueueThreadPerfStats getPerfStats();
+ @DoNotStrip
+ public fun getPerfStats(): MessageQueueThreadPerfStats?
- /**
- * Resets the perf counters. This is useful if the RN threads are being re-used. This method is
- * intended to be used for instrumentation purposes.
- */
- @DoNotStrip
- void resetPerfStats();
+ /**
+ * Resets the perf counters. This is useful if the RN threads are being re-used. This method is
+ * intended to be used for instrumentation purposes.
+ */
+ @DoNotStrip
+ public fun resetPerfStats()
- /** Returns true if the message queue is idle */
- @DoNotStrip
- boolean isIdle();
+ @DoNotStrip
+ public fun isIdle(): Boolean
}
diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/queue/MessageQueueThreadImpl.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/queue/MessageQueueThreadImpl.kt
index e15f70306ef77d..f8c3cd81772e55 100644
--- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/queue/MessageQueueThreadImpl.kt
+++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/queue/MessageQueueThreadImpl.kt
@@ -41,7 +41,7 @@ public class MessageQueueThreadImpl private constructor(
* if it is being submitted from the same queue Thread.
*/
@DoNotStrip
- override fun runOnQueue(runnable: Runnable): Boolean {
+ public override fun runOnQueue(runnable: Runnable): Boolean {
if (isFinished) {
FLog.w(
ReactConstants.TAG,
@@ -54,7 +54,7 @@ public class MessageQueueThreadImpl private constructor(
}
@DoNotStrip
- override fun callOnQueue(callable: Callable): Future {
+ public override fun callOnQueue(callable: Callable): Future {
val future = SimpleSettableFuture()
runOnQueue {
try {
@@ -80,7 +80,7 @@ public class MessageQueueThreadImpl private constructor(
@DoNotStrip
@Throws(AssertionException::class)
override fun assertIsOnThread() {
- assertCondition(isOnThread, assertionErrorMessage)
+ assertCondition(isOnThread(), assertionErrorMessage)
}
/**
@@ -88,9 +88,9 @@ public class MessageQueueThreadImpl private constructor(
*/
@DoNotStrip
@Throws(AssertionException::class)
- override fun assertIsOnThread(message: String) {
+ public override fun assertIsOnThread(message: String) {
assertCondition(
- isOnThread,
+ isOnThread(),
StringBuilder().append(assertionErrorMessage).append(" ").append(message).toString()
)
}
@@ -129,7 +129,7 @@ public class MessageQueueThreadImpl private constructor(
}
@DoNotStrip
- override fun isIdle(): Boolean {
+ public override fun isIdle(): Boolean {
return looper.queue.isIdle
}