blob: 98b4c8747057e319d0153e2010a85158181346dd [file]
#ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_HFT_CORE_SCHEDULER_H_
#define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_HFT_CORE_SCHEDULER_H_
#include "absl/functional/any_invocable.h"
#include "absl/time/time.h"
namespace milotic_hft {
// Dependency-free scheduling seam consumed by the HFT subscription manager
// core. The core schedules its per-subscription export tasks through this
// interface so it stays independent of any concrete scheduler implementation
// (and that implementation's transitive dependencies, e.g. boost::asio).
//
// The production implementation is milotic_tlbmc::HftTaskSchedulerAdapter,
// which wraps the shared tlbmc TaskScheduler. Tests may inject a fake.
class Scheduler {
public:
virtual ~Scheduler() = default;
// Schedules `task` for async invocation with the given `period`. `task` is
// invoked with an `on_done` callback that it must run when the work for that
// cycle is complete. Returns an opaque task id usable with Cancel.
virtual int ScheduleAsync(
absl::AnyInvocable<void(absl::AnyInvocable<void()>)> task,
absl::Duration period) = 0;
// Cancels the task previously returned by ScheduleAsync.
virtual void Cancel(int task_id) = 0;
// Stops the scheduler, cancelling all tasks and joining any worker threads.
virtual void Stop() = 0;
};
} // namespace milotic_hft
#endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_HFT_CORE_SCHEDULER_H_