1 //
2 // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 #pragma once
8 
9 #include "td/actor/actor.h"
10 #include "td/actor/PromiseFuture.h"
11 
12 #include "td/utils/common.h"
13 
14 namespace td {
15 
16 class SleepActor final : public Actor {
17  public:
SleepActor(double timeout,Promise<> promise)18   SleepActor(double timeout, Promise<> promise) : timeout_(timeout), promise_(std::move(promise)) {
19   }
20 
21  private:
22   double timeout_;
23   Promise<> promise_;
24 
start_up()25   void start_up() final {
26     set_timeout_in(timeout_);
27   }
timeout_expired()28   void timeout_expired() final {
29     promise_.set_value(Unit());
30     stop();
31   }
32 };
33 
34 template <>
35 class ActorTraits<SleepActor> {
36  public:
37   static constexpr bool need_context = false;
38   static constexpr bool need_start_up = true;
39 };
40 
41 }  // namespace td
42