added stop and wait functions into async launcher
All checks were successful
buildbot/DocsGenerator Build finished.
buildbot/LinuxCMakeBuilderQt6 Build finished.

This commit is contained in:
Andrei Yankovich 2025-04-07 20:19:25 +02:00
parent 6055fdc43d
commit fa092504fc
4 changed files with 36 additions and 1 deletions

View File

@ -35,6 +35,7 @@
return CONDITION; \
namespace QH {
Async::Async(QThread *thread, QObject *ptr):
QObject(ptr) {

View File

@ -6,6 +6,8 @@
*/
#include "asynclauncher.h"
#include <QThread>
namespace QH {
AsyncLauncher::AsyncLauncher(QThread *thread, QObject *ptr):
@ -14,7 +16,27 @@ AsyncLauncher::AsyncLauncher(QThread *thread, QObject *ptr):
bool AsyncLauncher::run(const Async::Job &action, bool wait) {
if (thread() && !thread()->isRunning()) {
thread()->start();
}
return asyncLauncher(action, wait);
}
bool AsyncLauncher::stop() {
if (thread() && thread()->isRunning()) {
thread()->exit();
}
return true;
}
bool AsyncLauncher::waitForStop() {
if (thread() && thread()->isRunning()) {
return thread()->wait();
}
return true;
}
}

View File

@ -47,6 +47,18 @@ public:
*/
bool run(const Job &action, bool wait = false);
/**
* @brief stop This method stop the work thread of this object.
* @return true if the thread is stopped.
*/
bool stop();
/**
* @brief waitForStop This method wait for the thread of this object is stopped.
* @return true if the thread is stopped.
*/
bool waitForStop();
};
}

View File

@ -132,7 +132,7 @@ public:
/**
* @brief stop This method stops the render loop.
*/
void stop();
virtual void stop();
/**
* @brief isRun This method returns the state of the render loop.