@@ -20,6 +20,7 @@ struct MultithreadingModule : jni::JavaClass<MultithreadingModule> {
2020public:
2121 __unused static constexpr auto kJavaDescriptor = " Lcom/reactnativemultithreading/MultithreadingModule;" ;
2222
23+ static constexpr auto TAG = " RNMultithreading" ;
2324
2425 static void registerNatives () {
2526 javaClassStatic ()->registerNatives ({
@@ -32,10 +33,11 @@ struct MultithreadingModule : jni::JavaClass<MultithreadingModule> {
3233 static std::shared_ptr<react::JSExecutorFactory> makeJSExecutorFactory () {
3334 ThreadScope scope; // JNI needs to attach this thread because this function is being called from a different Thread
3435
35- __android_log_write (ANDROID_LOG_DEBUG, " RNMultithreading " , " Calling Java method MultithreadingModule.makeJSExecutor()..." );
36+ __android_log_write (ANDROID_LOG_INFO, TAG , " Calling Java method MultithreadingModule.makeJSExecutor()..." );
3637 static const auto cls = javaClassStatic ();
3738 static const auto method = cls->getStaticMethod <react::JavaScriptExecutorHolder ()>(" makeJSExecutor" );
3839 auto result = method (cls);
40+ __android_log_write (ANDROID_LOG_INFO, TAG, " JavaScriptExecutor created! Getting factory..." );
3941 return result->cthis ()->getExecutorFactory ();
4042 }
4143
@@ -57,16 +59,22 @@ struct MultithreadingModule : jni::JavaClass<MultithreadingModule> {
5759 return std::make_shared<reanimated::AndroidErrorHandler>(scheduler_);
5860 };
5961 auto makeJsExecutor = []() -> std::unique_ptr<jsi::Runtime> {
60- __android_log_write (ANDROID_LOG_DEBUG, " RNMultithreading" , " Creating JSExecutor.." );
61- std::shared_ptr<react::ExecutorDelegate> delegate = std::shared_ptr<react::ExecutorDelegate>();
62- std::shared_ptr<react::MessageQueueThread> jsQueue = std::shared_ptr<react::MessageQueueThread>();
63- auto jsExecutorFactory = makeJSExecutorFactory ();
64- auto executor = jsExecutorFactory->createJSExecutor (delegate, jsQueue);
65- auto runtimePointer = static_cast <jsi::Runtime*>(executor->getJavaScriptContext ());
66- __android_log_write (ANDROID_LOG_DEBUG, " RNMultithreading" , " JSExecutor created!" );
67- std::unique_ptr<jsi::Runtime> runtime;
68- runtime.reset (runtimePointer);
69- return runtime;
62+ __android_log_write (ANDROID_LOG_DEBUG, TAG, " Creating JSExecutorFactory.." );
63+ try {
64+ std::shared_ptr<react::ExecutorDelegate> delegate = std::shared_ptr<react::ExecutorDelegate>();
65+ std::shared_ptr<react::MessageQueueThread> jsQueue = std::shared_ptr<react::MessageQueueThread>();
66+ auto jsExecutorFactory = makeJSExecutorFactory ();
67+ __android_log_write (ANDROID_LOG_DEBUG, TAG, " Creating JSExecutor.." );
68+ auto executor = jsExecutorFactory->createJSExecutor (delegate,
69+ jsQueue);
70+ auto runtimePointer = static_cast <jsi::Runtime *>(executor->getJavaScriptContext ());
71+ __android_log_write (ANDROID_LOG_DEBUG, TAG, " JSExecutor created!" );
72+ return std::unique_ptr<jsi::Runtime>(runtimePointer);
73+ } catch (std::exception& exc) {
74+ __android_log_write (ANDROID_LOG_ERROR, TAG, " Failed to create JSExecutor!" );
75+ __android_log_write (ANDROID_LOG_ERROR, TAG, exc.what ());
76+ return std::unique_ptr<jsi::Runtime>(); // TODO: Remove this and let the caller handle the exception.
77+ }
7078 };
7179 mrousavy::multithreading::install (*runtime, makeJsExecutor, makeScheduler, makeErrorHandler);
7280
0 commit comments