From d966a0a9913709c7d62362e686fe8638dac0461a Mon Sep 17 00:00:00 2001 From: Dennis Klein Date: Mon, 28 Jan 2019 13:25:41 +0100 Subject: [PATCH] Handle some edge cases --- fairmq/plugins/DDS/runDDSCommandUI.cxx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/fairmq/plugins/DDS/runDDSCommandUI.cxx b/fairmq/plugins/DDS/runDDSCommandUI.cxx index b2e92823..2d141300 100644 --- a/fairmq/plugins/DDS/runDDSCommandUI.cxx +++ b/fairmq/plugins/DDS/runDDSCommandUI.cxx @@ -153,15 +153,21 @@ void waitMode(const string& waitForState, StateSubscription stateSubscription(topologyPath, ddsCustomCmd); auto condition = [&] { - return all_of(waitForStateMap.cbegin(), - waitForStateMap.cend(), - [&](WaitForStateMap::value_type i) { return i.second == waitForState; }); + return !waitForStateMap.empty() // TODO once DDS provides an API to retrieve actual number of tasks, use it here + && all_of(waitForStateMap.cbegin(), + waitForStateMap.cend(), + [&](WaitForStateMap::value_type i) { return i.second == waitForState; }); }; unique_lock lock(waitForStateMutex); - if (!waitForStateCV.wait_for(lock, timeout, condition)) { - throw runtime_error("timeout"); - }; + + if (timeout > std::chrono::milliseconds(0)) { + if (!waitForStateCV.wait_for(lock, timeout, condition)) { + throw runtime_error("timeout"); + } + } else { + waitForStateCV.wait(lock, condition); + } } int main(int argc, char* argv[])