proxygen
ScheduledExecutor.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <chrono>
20 #include <memory>
21 #include <stdexcept>
22 
23 #include <folly/Executor.h>
24 #include <folly/lang/Exception.h>
25 
26 namespace folly {
27 // An executor that supports timed scheduling. Like RxScheduler.
28 class ScheduledExecutor : public virtual Executor {
29  public:
30  // Reality is that better than millisecond resolution is very hard to
31  // achieve. However, we reserve the right to be incredible.
32  typedef std::chrono::microseconds Duration;
33  typedef std::chrono::steady_clock::time_point TimePoint;
34 
35  ~ScheduledExecutor() override = default;
36 
37  void add(Func) override = 0;
38 
40  void schedule(Func&& a) {
41  add(std::move(a));
42  }
43 
46  void schedule(Func&& a, Duration const& dur) {
47  scheduleAt(std::move(a), now() + dur);
48  }
49 
52  virtual void scheduleAt(Func&& /* a */, TimePoint const& /* t */) {
53  throw_exception<std::logic_error>("unimplemented");
54  }
55 
57  virtual TimePoint now() {
59  }
60 };
61 } // namespace folly
void add(Func) override=0
std::chrono::steady_clock::time_point TimePoint
std::chrono::steady_clock::time_point now()
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
void schedule(Func &&a)
Alias for add() (for Rx consistency)
std::chrono::microseconds Duration
~ScheduledExecutor() override=default
virtual TimePoint now()
Get this executor&#39;s notion of time. Must be threadsafe.
char a
virtual void scheduleAt(Func &&, TimePoint const &)
void schedule(Func &&a, Duration const &dur)