From 820f9633f15aa20a03a44348012e98d6bd5e6bd9 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 19 Aug 2015 19:53:24 +0200 Subject: Got transactions to work. With an ugly hack, we'll need to solve this in the messagequeue properly. --- common/genericresource.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'common') diff --git a/common/genericresource.cpp b/common/genericresource.cpp index 943f7d2..e2b0122 100644 --- a/common/genericresource.cpp +++ b/common/genericresource.cpp @@ -195,12 +195,13 @@ void GenericResource::processCommand(int commandId, const QByteArray &data) mUserQueue.startTransaction(); enqueueCommand(mUserQueue, commandId, data); modifications++; - // if (modifications >= 100) { + if (modifications >= 100) { mUserQueue.commit(); - // modifications = 0; - // } else { - // mCommitQueueTimer.start(); - // } + modifications = 0; + mCommitQueueTimer.stop(); + } else { + mCommitQueueTimer.start(); + } } static void waitForDrained(KAsync::Future &f, MessageQueue &queue) @@ -220,6 +221,14 @@ KAsync::Job GenericResource::processAllMessages() //TODO: report errors while processing sync? //TODO JOBAPI: A helper that waits for n events and then continues? return KAsync::start([this](KAsync::Future &f) { + if (mCommitQueueTimer.isActive()) { + QObject::connect(&mCommitQueueTimer, &QTimer::timeout, [&f]() { + f.setFinished(); + }); + } else { + f.setFinished(); + } + }).then([this](KAsync::Future &f) { waitForDrained(f, mSynchronizerQueue); }).then([this](KAsync::Future &f) { waitForDrained(f, mUserQueue); -- cgit v1.2.3