2 * Copyright 2017 Facebook, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <folly/Executor.h>
24 * A DrivableExecutor can be driven via its drive() method
25 * Examples include EventBase (via loopOnce()) and ManualExecutor
26 * (via makeProgress()).
28 * This interface is most handy in conjunction with
29 * Future<T>::getVia(DrivableExecutor*) and
30 * Future<T>::waitVia(DrivableExecutor*)
32 * These call drive() * repeatedly until the Future is fulfilled.
33 * getVia() returns the value (or throws the exception) and waitVia() returns
34 * the same Future for chainability.
36 * These will be most helpful in tests, for instance if you need to pump a mock
37 * EventBase until Futures complete.
40 class DrivableExecutor : public virtual Executor {
42 ~DrivableExecutor() override = default;
44 // Make progress on this Executor's work.
46 // Drive *must not* busy wait if there is no work to do. Instead,
47 // sleep (using a semaphore or similar) until at least one event is
49 // I.e. make_future().via(foo).then(...).getVia(DrivableExecutor)
50 // must not spin, even though nothing happens on the drivable
52 virtual void drive() = 0;