diff options
author | Yuri Wiitala <miu@chromium.org> | 2020-02-20 13:41:54 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-02-20 22:40:46 +0000 |
commit | c681b47a0955c52eacdbe6739c724be697ab0137 (patch) | |
tree | fb3c616fb32536d68789ccf522c6649a4b29dafc /util/alarm.h | |
parent | f14fa29a7b1dc243b947b8366f691dfb2ac202cb (diff) | |
download | openscreen-c681b47a0955c52eacdbe6739c724be697ab0137.tar.gz |
Clarify Alarm::Schedule() API with kImmediately.
Alarm::Schedule() was often being call with a {} time_point argument, to
request the task be run immediately. Instead, add a kImmediately
constant to make it clear to readers of the calling code what is
intended.
This change also makes minor changes inside the Alarm::Schedule()
implementation to prevent underflow in the delay calculations when
kImmediately is used.
Change-Id: I22e6f0d5ac4c1fd6926c8d20dd5332acd538ca68
Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/2057807
Commit-Queue: Yuri Wiitala <miu@chromium.org>
Reviewed-by: Max Yakimakha <yakimakha@chromium.org>
Diffstat (limited to 'util/alarm.h')
-rw-r--r-- | util/alarm.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/util/alarm.h b/util/alarm.h index f87127d8..551c0b76 100644 --- a/util/alarm.h +++ b/util/alarm.h @@ -43,7 +43,8 @@ class Alarm { // Schedule the |functor| to be invoked at |alarm_time|. If this Alarm was // already scheduled, the prior scheduling is canceled. The Functor can be any // callable target (e.g., function, lambda-expression, std::bind result, - // etc.). + // etc.). If |alarm_time| is on or before "now," such as kImmediately, it is + // scheduled to run as soon as possible. template <typename Functor> inline void Schedule(Functor functor, Clock::time_point alarm_time) { ScheduleWithTask(TaskRunner::Task(std::move(functor)), alarm_time); @@ -65,6 +66,9 @@ class Alarm { // they already have a Task to pass-in. void ScheduleWithTask(TaskRunner::Task task, Clock::time_point alarm_time); + // A special time_point value representing "as soon as possible." + static constexpr Clock::time_point kImmediately = Clock::time_point::min(); + private: // A move-only functor that holds a raw pointer back to |this| and can be // canceled before its call operator is invoked. When canceled, its call |