From 3be442eb322324804486064dddf2458dc2d17bc5 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 8 Apr 2015 09:59:14 +0200 Subject: async simplifications --- synchronizer/listener.cpp | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'synchronizer') diff --git a/synchronizer/listener.cpp b/synchronizer/listener.cpp index 2e1e918..edd9123 100644 --- a/synchronizer/listener.cpp +++ b/synchronizer/listener.cpp @@ -212,26 +212,16 @@ void Listener::processCommand(int commandId, uint messageId, Client &client, uin Warning() << "No resource loaded"; break; } - //TODO a more elegant composition of jobs should be possible + auto job = Async::null(); if (buffer->sourceSync()) { - bool localSync = buffer->localSync(); - m_resource->synchronizeWithSource(m_pipeline).then([callback, localSync, this](Async::Future &f){ - if (localSync) { - m_resource->processAllMessages().then([callback](Async::Future &f){ - callback(); - f.setFinished(); - }).exec(); - } else { - callback(); - f.setFinished(); - } - }).exec(); - } else if (buffer->localSync()) { - m_resource->processAllMessages().then([callback](Async::Future &f){ - callback(); - f.setFinished(); - }).exec(); + job = m_resource->synchronizeWithSource(m_pipeline); } + if (buffer->localSync()) { + job = job.then(m_resource->processAllMessages()); + } + job.then([callback]() { + callback(); + }).exec(); return; } else { Warning() << "received invalid command"; -- cgit v1.2.3