Line data Source code
1 : #pragma once 2 : 3 : #include <functional> 4 : #include <memory> 5 : 6 : #include "envoy/common/pure.h" 7 : 8 : namespace Envoy { 9 : namespace Event { 10 : 11 : /** 12 : * Callback wrapper that allows direct scheduling of callbacks in the event loop. 13 : */ 14 : class SchedulableCallback { 15 : public: 16 8329 : virtual ~SchedulableCallback() = default; 17 : 18 : /** 19 : * Schedule the callback so it runs in the current iteration of the event loop after all events 20 : * scheduled in the current event loop have had a chance to execute. 21 : */ 22 : virtual void scheduleCallbackCurrentIteration() PURE; 23 : 24 : /** 25 : * Schedule the callback so it runs in the next iteration of the event loop. There are no 26 : * ordering guarantees for callbacks scheduled for the next iteration, not even among 27 : * next-iteration callbacks. 28 : */ 29 : virtual void scheduleCallbackNextIteration() PURE; 30 : 31 : /** 32 : * Cancel pending execution of the callback. 33 : */ 34 : virtual void cancel() PURE; 35 : 36 : /** 37 : * Return true whether the SchedulableCallback is scheduled for execution. 38 : */ 39 : virtual bool enabled() PURE; 40 : }; 41 : 42 : using SchedulableCallbackPtr = std::unique_ptr<SchedulableCallback>; 43 : 44 : /** 45 : * SchedulableCallback factory. 46 : */ 47 : class CallbackScheduler { 48 : public: 49 1498 : virtual ~CallbackScheduler() = default; 50 : 51 : /** 52 : * Create a schedulable callback. 53 : */ 54 : virtual SchedulableCallbackPtr createSchedulableCallback(const std::function<void()>& cb) PURE; 55 : }; 56 : 57 : } // namespace Event 58 : } // namespace Envoy