Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32625971
D5578.1767474322.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.1767474322.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>
@@ -36,6 +37,26 @@
});
}
+ 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()) {
+ jsInvoker->invokeAsync(
+ [promise]() { promise->reject(TASK_CANCELLED_FLAG); });
+ return;
+ }
+
+ scheduleOrRunCommonImpl([this, task, promise, jsInvoker]() {
+ if (this->tasksCancelled.load()) {
+ jsInvoker->invokeAsync(
+ [promise]() { promise->reject(TASK_CANCELLED_FLAG); });
+ return;
+ }
+ task();
+ });
+ }
+
void enableMultithreadingCommonImpl() {
if (this->databaseThread == nullptr) {
this->databaseThread = std::make_unique<WorkerThread>("database");
@@ -47,6 +68,10 @@
static GlobalDBSingleton instance;
void scheduleOrRun(const taskType task);
void scheduleOrRunCancellable(const taskType task);
+ void scheduleOrRunCancellable(
+ const taskType task,
+ const std::shared_ptr<facebook::react::Promise> promise,
+ const std::shared_ptr<facebook::react::CallInvoker> jsInvoker);
void enableMultithreading();
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->scheduleOrRunCancellableCommonImpl(task, promise, jsInvoker);
+ });
+}
+
void GlobalDBSingleton::enableMultithreading() {
if (NSThread.isMainThread) {
this->enableMultithreadingCommonImpl();
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 3, 9:05 PM (12 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5890747
Default Alt Text
D5578.1767474322.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