aboutsummaryrefslogtreecommitdiff
path: root/src/daemon
diff options
context:
space:
mode:
authorxiphon <xiphon@protonmail.com>2019-06-20 20:28:59 +0000
committerxiphon <xiphon@protonmail.com>2019-06-24 20:09:50 +0000
commitbe7810c5a877898d792cc7d4406dc05c3280b38f (patch)
tree50810c88e2cfd8936c91a806b68f188e41f7e9dc /src/daemon
parentc7956f76ead2c82a320c830a63ffa97d55a10bb6 (diff)
downloadmonzero-gui-be7810c5a877898d792cc7d4406dc05c3280b38f.tar.gz
monzero-gui-be7810c5a877898d792cc7d4406dc05c3280b38f.tar.xz
monzero-gui-be7810c5a877898d792cc7d4406dc05c3280b38f.zip
qt: implement FutureScheduler, always await async code to complete
Diffstat (limited to 'src/daemon')
-rw-r--r--src/daemon/DaemonManager.cpp28
-rw-r--r--src/daemon/DaemonManager.h4
2 files changed, 15 insertions, 17 deletions
diff --git a/src/daemon/DaemonManager.cpp b/src/daemon/DaemonManager.cpp
index 136e72bd..ecbe1784 100644
--- a/src/daemon/DaemonManager.cpp
+++ b/src/daemon/DaemonManager.cpp
@@ -131,19 +131,12 @@ bool DaemonManager::start(const QString &flags, NetworkType::Type nettype, const
}
// Start start watcher
- QFuture<bool> future = QtConcurrent::run(this, &DaemonManager::startWatcher, nettype);
- QFutureWatcher<bool> * watcher = new QFutureWatcher<bool>();
- connect(watcher, &QFutureWatcher<bool>::finished,
- this, [this, watcher]() {
- QFuture<bool> future = watcher->future();
- watcher->deleteLater();
- if(future.result())
+ m_scheduler.run([this, nettype] {
+ if (startWatcher(nettype))
emit daemonStarted();
else
emit daemonStartFailure();
});
- watcher->setFuture(future);
-
return true;
}
@@ -155,17 +148,12 @@ bool DaemonManager::stop(NetworkType::Type nettype)
qDebug() << message;
// Start stop watcher - Will kill if not shutting down
- QFuture<bool> future = QtConcurrent::run(this, &DaemonManager::stopWatcher, nettype);
- QFutureWatcher<bool> * watcher = new QFutureWatcher<bool>();
- connect(watcher, &QFutureWatcher<bool>::finished,
- this, [this, watcher]() {
- QFuture<bool> future = watcher->future();
- watcher->deleteLater();
- if(future.result()) {
+ m_scheduler.run([this, nettype] {
+ if (stopWatcher(nettype))
+ {
emit daemonStopped();
}
});
- watcher->setFuture(future);
return true;
}
@@ -330,6 +318,7 @@ QVariantMap DaemonManager::validateDataDir(const QString &dataDir) const
DaemonManager::DaemonManager(QObject *parent)
: QObject(parent)
+ , m_scheduler(this)
{
// Platform depetent path to monerod
@@ -344,3 +333,8 @@ DaemonManager::DaemonManager(QObject *parent)
m_has_daemon = false;
}
}
+
+DaemonManager::~DaemonManager()
+{
+ m_scheduler.shutdownWaitForFinished();
+}
diff --git a/src/daemon/DaemonManager.h b/src/daemon/DaemonManager.h
index e85152ba..6063c8cb 100644
--- a/src/daemon/DaemonManager.h
+++ b/src/daemon/DaemonManager.h
@@ -33,6 +33,7 @@
#include <QUrl>
#include <QProcess>
#include <QVariantMap>
+#include "qt/FutureScheduler.h"
#include "NetworkType.h"
class DaemonManager : public QObject
@@ -71,6 +72,8 @@ public slots:
private:
explicit DaemonManager(QObject *parent = 0);
+ ~DaemonManager();
+
static DaemonManager * m_instance;
static QStringList m_clArgs;
QProcess *m_daemon;
@@ -79,6 +82,7 @@ private:
bool m_has_daemon = true;
bool m_app_exit = false;
+ FutureScheduler m_scheduler;
};
#endif // DAEMONMANAGER_H