From 61b3dfd1844799d29ac1f090a1e674d5a3439dc7 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 30 Nov 2016 09:55:05 +0000 Subject: [PATCH] Use a Timer for Shell waiting notification Without a timer we were relying on other event sources to wake us up to display the information, which was usually a NormalIdle or a filesystem check timer. --- src/shell_manager.cc | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/shell_manager.cc b/src/shell_manager.cc index 1ee1c280..698c7fc7 100644 --- a/src/shell_manager.cc +++ b/src/shell_manager.cc @@ -191,7 +191,14 @@ std::pair ShellManager::eval( using namespace std::chrono; static constexpr seconds wait_timeout{1}; - auto next_wait_notification = duration_cast(wait_timeout); + Timer wait_timer{wait_time + wait_timeout, [&](Timer& timer) + { + auto wait_duration = Clock::now() - wait_time; + context.print_status({ format("waiting for shell command to finish ({}s)", + duration_cast(wait_duration).count()), + get_face("Information") }, true); + timer.set_next_date(Clock::now() + wait_timeout); + }, EventMode::Urgent}; while (not terminated or ((flags & Flags::WaitForStdout) and @@ -200,15 +207,6 @@ std::pair ShellManager::eval( EventManager::instance().handle_next_events(EventMode::Urgent, &orig_mask); if (not terminated) terminated = waitpid(pid, &status, WNOHANG); - - auto wait_duration = Clock::now() - wait_time; - if (wait_duration > next_wait_notification) - { - next_wait_notification = duration_cast(wait_duration + wait_timeout); - context.print_status({ format("waiting for shell command to finish ({}s)", - duration_cast(wait_duration).count()), - get_face("Information") }, true); - } } if (not stderr_contents.empty())