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 @@ -1062,7 +1062,8 @@ 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(); @@ -1076,7 +1077,10 @@ promise->resolve(jsi::Value::undefined()); } }); - }); + GlobalDBSingleton::instance.scheduleOrRun( + []() { GlobalDBSingleton::instance.setTasksCancelled(false); }); + }; + 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) {