Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32614951
D5578.1767455193.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D5578.1767455193.diff
View Options
diff --git a/native/android/app/src/cpp/GlobalDBSingleton.cpp b/native/android/app/src/cpp/GlobalDBSingleton.cpp
--- a/native/android/app/src/cpp/GlobalDBSingleton.cpp
+++ b/native/android/app/src/cpp/GlobalDBSingleton.cpp
@@ -18,6 +18,13 @@
this->scheduleOrRunCancellableCommonImpl(task);
}
+void GlobalDBSingleton::scheduleOrRunCancellable(
+ const taskType task,
+ const std::shared_ptr<facebook::react::Promise> promise,
+ const std::shared_ptr<facebook::react::CallInvoker> jsInvoker) {
+ this->scheduleOrRunCancellableCommonImpl(task, promise, jsInvoker);
+}
+
void GlobalDBSingleton::enableMultithreading() {
this->enableMultithreadingCommonImpl();
}
diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h
--- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h
+++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h
@@ -5,6 +5,7 @@
#include "../Tools/WorkerThread.h"
#include "../_generated/NativeModules.h"
#include "../grpc/Client.h"
+#include <ReactCommon/TurboModuleUtils.h>
#include <jsi/jsi.h>
#include <memory>
diff --git a/native/cpp/CommonCpp/NativeModules/InternalModules/GlobalDBSingleton.h b/native/cpp/CommonCpp/NativeModules/InternalModules/GlobalDBSingleton.h
--- a/native/cpp/CommonCpp/NativeModules/InternalModules/GlobalDBSingleton.h
+++ b/native/cpp/CommonCpp/NativeModules/InternalModules/GlobalDBSingleton.h
@@ -1,6 +1,7 @@
#pragma once
#include "../../Tools/WorkerThread.h"
+#include <ReactCommon/TurboModuleUtils.h>
#include <atomic>
@@ -38,6 +39,37 @@
task();
}
+ void scheduleOrRunCancellableCommonImpl(
+ const taskType task,
+ const std::shared_ptr<facebook::react::Promise> promise,
+ const std::shared_ptr<facebook::react::CallInvoker> jsInvoker) {
+ if (this->tasksCancelled.load()) {
+ std::string error = "TASK_CANCELLED";
+ jsInvoker->invokeAsync([=]() {
+ promise->reject(error);
+ return;
+ });
+ return;
+ }
+
+ if (this->databaseThread != nullptr) {
+ this->databaseThread->scheduleTask([this, task, promise, jsInvoker]() {
+ if (this->tasksCancelled.load()) {
+ std::string error = "TASK_CANCELLED";
+ jsInvoker->invokeAsync([error, promise]() {
+ promise->reject(error);
+ return;
+ });
+ } else {
+ task();
+ }
+ });
+ return;
+ }
+
+ task();
+ }
+
void enableMultithreadingCommonImpl() {
if (this->databaseThread == nullptr) {
this->databaseThread = std::make_unique<WorkerThread>("database");
@@ -50,6 +82,10 @@
void scheduleOrRun(const taskType task);
void scheduleOrRunCancellable(const taskType task);
void enableMultithreading();
+ void scheduleOrRunCancellable(
+ const taskType task,
+ const std::shared_ptr<facebook::react::Promise> promise,
+ const std::shared_ptr<facebook::react::CallInvoker> jsInvoker);
void setTasksCancelled(bool tasksCancelled) {
this->tasksCancelled.store(tasksCancelled);
}
diff --git a/native/ios/Comm/GlobalDBSingleton.mm b/native/ios/Comm/GlobalDBSingleton.mm
--- a/native/ios/Comm/GlobalDBSingleton.mm
+++ b/native/ios/Comm/GlobalDBSingleton.mm
@@ -1,5 +1,6 @@
#import "GlobalDBSingleton.h"
#import <Foundation/Foundation.h>
+#include <ReactCommon/TurboModuleUtils.h>
namespace comm {
GlobalDBSingleton GlobalDBSingleton::instance;
@@ -32,6 +33,20 @@
});
}
+void GlobalDBSingleton::scheduleOrRunCancellable(
+ const taskType task,
+ const std::shared_ptr<facebook::react::Promise> promise,
+ const std::shared_ptr<facebook::react::CallInvoker> jsInvoker) {
+ if (NSThread.isMainThread || this->multithreadingEnabled.load()) {
+ this->scheduleOrRunCancellableCommonImpl(task, promise, jsInvoker);
+ return;
+ }
+
+ dispatch_async(dispatch_get_main_queue(), ^{
+ this->scheduleOrRunCommonImpl(task);
+ });
+}
+
void GlobalDBSingleton::enableMultithreading() {
if (NSThread.isMainThread) {
this->enableMultithreadingCommonImpl();
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 3, 3:46 PM (3 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5889601
Default Alt Text
D5578.1767455193.diff (3 KB)
Attached To
Mode
D5578: [native] implement method to run asynchronous cancellable task in CommCoreModule and return error via promise
Attached
Detach File
Event Timeline
Log In to Comment