diff --git a/src/sled/task_queue/pending_task_safety_flag.h b/src/sled/task_queue/pending_task_safety_flag.h index 502cdaa..ba2815f 100644 --- a/src/sled/task_queue/pending_task_safety_flag.h +++ b/src/sled/task_queue/pending_task_safety_flag.h @@ -54,16 +54,6 @@ private: scoped_refptr flag_; }; -template>::value>> -std::function(Args &&...)> -SafeTask(scoped_refptr flag, F &&f) -{ - return [flag, f](Args &&...args) mutable -> InvokeResultT { - if (flag->alive()) { return f(std::forward(args)...); } - return {}; - }; -} - template>::value>> std::function SafeTask(scoped_refptr flag, F &&f) diff --git a/src/sled/timer/timer.cc b/src/sled/timer/timer.cc index e1d6bce..0d5cbf3 100644 --- a/src/sled/timer/timer.cc +++ b/src/sled/timer/timer.cc @@ -109,7 +109,7 @@ Timer::Trigger(TimerGeneration generation) } } -std::unique_ptr +Timer::Ptr TimerManager::CreateTimer(const std::string &name, Timer::OnExpired on_expired, TaskQueueBase *owner) { next_id_ = TimerID(next_id_ + 1); @@ -128,6 +128,17 @@ TimerManager::CreateTimer(const std::string &name, Timer::OnExpired on_expired, return unique_timer; } +Timer::Ptr +TimerManager::CreateTimer(const std::string &name, Timer::OnVoidExpired on_void_expired, TaskQueueBase *owner) +{ + Timer::OnExpired on_expired = [on_void_expired]() { + on_void_expired(); + return sled::nullopt; + }; + + return CreateTimer(name, on_expired, owner); +} + void TimerManager::HandleTimeout(TimeoutID id) { diff --git a/src/sled/timer/timer.h b/src/sled/timer/timer.h index 05c6aa7..61eddc1 100644 --- a/src/sled/timer/timer.h +++ b/src/sled/timer/timer.h @@ -30,6 +30,7 @@ public: using Ptr = std::unique_ptr; using OnExpired = std::function()>; + using OnVoidExpired = std::function; Timer(const Timer &) = delete; Timer &operator=(const Timer &) = delete; ~Timer(); @@ -78,6 +79,8 @@ public: std::unique_ptr CreateTimer(const std::string &name, Timer::OnExpired on_expired, TaskQueueBase *owner = nullptr); + std::unique_ptr + CreateTimer(const std::string &name, Timer::OnVoidExpired on_void_expired, TaskQueueBase *owner = nullptr); void HandleTimeout(TimeoutID timeout_id); private: