11#include <QCoreApplication>
18#include <qaglobalutils.h>
21#define waitPrivate(CONDITION, TIMEOUT) \
22 auto curmsec = QDateTime::currentMSecsSinceEpoch() + TIMEOUT; \
23 while (curmsec > QDateTime::currentMSecsSinceEpoch() && !CONDITION) { \
24 QCoreApplication::processEvents(); \
26 QCoreApplication::processEvents(); \
30#define freazePrivate(CONDITION, TIMEOUT) \
31 auto curmsec = QDateTime::currentMSecsSinceEpoch() + TIMEOUT; \
32 while (curmsec > QDateTime::currentMSecsSinceEpoch() && !CONDITION) { \
33 std::this_thread::sleep_for(std::chrono::microseconds(1)); \
41 threadAnalize(thread);
49void Async::asyncHandler(Job job,
51 bool *resultOfWork)
const {
55 if (endOfWork && resultOfWork)
56 *resultOfWork = result;
63void Async::threadAnalize(QThread *thread) {
66 debug_assert((mainThread != thread) && thread,
"You try create async object into main thread");
82 if (QThread::currentThread() == thread()) {
86 if (!thread()->isRunning()) {
88 qCritical() <<
"The work threand of the async object is not running";
94 return QMetaObject::invokeMethod(
const_cast<Async*
>(
this),
100 bool workOfEnd =
false, workResult =
false;
102 bool invockeResult = QMetaObject::invokeMethod(
const_cast<Async*
>(
this),
104 Qt::QueuedConnection,
106 Q_ARG(
bool*, &workOfEnd),
107 Q_ARG(
bool*, &workResult));
120bool Async::waitFor(
const std::function<
bool ()> &condition,
int timeout,
bool freaze)
const {
#define freazePrivate(CONDITION, TIMEOUT)
#define waitPrivate(CONDITION, TIMEOUT)
static QThread * mainThreadID()
mainThreadID This method return the pointer to main thread
The Async class This is bundle of async templates and async wrappers.
std::function< bool()> Job
Async(QThread *thread, QObject *ptr=nullptr)
Async This is default constructor of the async object.
bool waitFor(bool *condition, int timeout=WAIT_TIME, bool freaze=true) const
waitFor This is base wait function.
bool asyncLauncher(const Job &job, bool await=false, bool freaze=true) const
asyncLauncher This method invoke a job on the thread (using the asyncHandler method) of this object.
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...