This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-Qt/example/doric/async/DoricAsyncResult.cpp
2021-07-21 19:03:29 +08:00

32 lines
711 B
C++

#include "DoricAsyncResult.h"
#include <QWaitCondition>
DoricAsyncResult::DoricAsyncResult() {}
void DoricAsyncResult::setResult(QString result) {
this->result = result;
this->resultCallback();
}
void DoricAsyncResult::setError(QString exception) { this->result = exception; }
bool DoricAsyncResult::hasResult() { return !(result.isEmpty()); }
QString DoricAsyncResult::getResult() { return this->result; }
QString DoricAsyncResult::waitUntilResult() {
if (hasResult()) {
return this->result;
}
QMutex mutex;
QWaitCondition condition;
this->resultCallback = [&condition]() { condition.wakeAll(); };
mutex.lock();
condition.wait(&mutex);
mutex.unlock();
return this->result;
}