Skip to content

Commit 89faf0c

Browse files
MrMannWoodfacebook-github-bot
authored andcommitted
Added saftey for ensuring callback is called
Summary: Adds a return value to `MessageQueueThread#runOnQueue`, it's implementors and one caller. It is currently possible for a callback to not be called (because the HandlerThread has been shutdown). If the callback is mission-critical (frees resources, releases a lock, etc) the callee has no indication that it needs to do something. This surfaces that information to the callee. Changelog: [Android][Changed] - Made `MessageQueueThread#runOnQueue` return a boolean. Made `MessageQueueThreadImpl#runOnQueue` return false when the runnable is not submitted. Reviewed By: RSNara Differential Revision: D33075516 fbshipit-source-id: bd214a39ae066c0e7d413f2eaaaa05bd072ead2a
1 parent 19174a5 commit 89faf0c

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ public boolean isOnJSQueueThread() {
396396
return Assertions.assertNotNull(mJSMessageQueueThread).isOnThread();
397397
}
398398

399-
public void runOnJSQueueThread(Runnable runnable) {
400-
Assertions.assertNotNull(mJSMessageQueueThread).runOnQueue(runnable);
399+
public boolean runOnJSQueueThread(Runnable runnable) {
400+
return Assertions.assertNotNull(mJSMessageQueueThread).runOnQueue(runnable);
401401
}
402402

403403
/**

ReactAndroid/src/main/java/com/facebook/react/bridge/queue/MessageQueueThread.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public interface MessageQueueThread {
1919
* if it is being submitted from the same queue Thread.
2020
*/
2121
@DoNotStrip
22-
void runOnQueue(Runnable runnable);
22+
boolean runOnQueue(Runnable runnable);
2323

2424
/**
2525
* Runs the given Callable on this Thread. It will be submitted to the end of the event queue even

ReactAndroid/src/main/java/com/facebook/react/bridge/queue/MessageQueueThreadImpl.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,17 @@ private MessageQueueThreadImpl(
5555
*/
5656
@DoNotStrip
5757
@Override
58-
public void runOnQueue(Runnable runnable) {
58+
public boolean runOnQueue(Runnable runnable) {
5959
if (mIsFinished) {
6060
FLog.w(
6161
ReactConstants.TAG,
6262
"Tried to enqueue runnable on already finished thread: '"
6363
+ getName()
6464
+ "... dropping Runnable.");
65+
return false;
6566
}
6667
mHandler.post(runnable);
68+
return true;
6769
}
6870

6971
@DoNotStrip

ReactAndroid/src/main/jni/react/jni/JMessageQueueThread.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void JMessageQueueThread::runOnQueue(std::function<void()> &&runnable) {
6969
jni::ThreadScope guard;
7070
static auto method =
7171
JavaMessageQueueThread::javaClassStatic()
72-
->getMethod<void(Runnable::javaobject)>("runOnQueue");
72+
->getMethod<jboolean(Runnable::javaobject)>("runOnQueue");
7373
method(
7474
m_jobj,
7575
JNativeRunnable::newObjectCxxArgs(wrapRunnable(std::move(runnable)))

0 commit comments

Comments
 (0)