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 @@ -6,7 +6,8 @@ GlobalDBSingleton::GlobalDBSingleton() : multithreadingEnabled(true), - databaseThread(std::make_unique("database")) { + databaseThread(std::make_unique("database")), + tasksCancelled(false) { } void GlobalDBSingleton::scheduleOrRun(const taskType task) { diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp --- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp +++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp @@ -1058,13 +1058,15 @@ jsi::Value CommCoreModule::clearSensitiveData(jsi::Runtime &rt) { return createPromiseAsJSIValue( rt, [this](jsi::Runtime &innerRt, std::shared_ptr promise) { - GlobalDBSingleton::instance.scheduleOrRun([this, promise]() { + GlobalDBSingleton::instance.setTasksCancelled(true); + taskType job = [this, promise]() { std::string error; try { DatabaseManager::getQueryExecutor().clearSensitiveData(); } catch (const std::exception &e) { error = e.what(); } + GlobalDBSingleton::instance.setTasksCancelled(false); this->jsInvoker_->invokeAsync([error, promise]() { if (error.size()) { promise->reject(error); @@ -1072,7 +1074,8 @@ promise->resolve(jsi::Value::undefined()); } }); - }); + }; + GlobalDBSingleton::instance.scheduleOrRun(job); }); } 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 @@ -8,6 +8,7 @@ class GlobalDBSingleton { std::atomic multithreadingEnabled; std::unique_ptr databaseThread; + std::atomic tasksCancelled; GlobalDBSingleton(); @@ -30,5 +31,8 @@ static GlobalDBSingleton instance; void scheduleOrRun(const taskType task); void enableMultithreading(); + void setTasksCancelled(bool tasksCancelled) { + this->tasksCancelled.store(tasksCancelled); + } }; } // namespace comm 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 @@ -5,7 +5,9 @@ GlobalDBSingleton GlobalDBSingleton::instance; GlobalDBSingleton::GlobalDBSingleton() - : multithreadingEnabled(false), databaseThread(nullptr) { + : multithreadingEnabled(false), + databaseThread(nullptr), + tasksCancelled(false) { } void GlobalDBSingleton::scheduleOrRun(const taskType task) {