Quantum Resource Manager and Compiler Infrastructure (QRM&CI) 0.1.0
PublicationThrottle.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026 MQSS Maintainers
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 */
7
11
12#pragma once
13
14#include <chrono>
15#include <optional>
16
17namespace mqss::qrmci {
18
28public:
30 using Clock = std::chrono::steady_clock;
31
34 static constexpr Clock::duration DefaultInterval = std::chrono::seconds(5);
35
38 explicit PublicationThrottle(Clock::duration interval = DefaultInterval)
39 : publishInterval(interval) {}
40
50 [[nodiscard]] bool claim(Clock::time_point now = Clock::now()) {
51 if (lastClaimed.has_value() && now - *lastClaimed < publishInterval) {
52 return false;
53 }
54 lastClaimed = now;
55 return true;
56 }
57
60 [[nodiscard]] Clock::duration getInterval() const noexcept {
61 return publishInterval;
62 }
63
64private:
65 Clock::duration publishInterval;
66 std::optional<Clock::time_point> lastClaimed;
67};
68
69} // namespace mqss::qrmci
std::chrono::steady_clock Clock
Monotonic clock used for slot timing.
PublicationThrottle(Clock::duration interval=DefaultInterval)
Construct a throttle with the given interval.
static constexpr Clock::duration DefaultInterval
Minimum spacing between two publish slots, absent an explicit interval.
Clock::duration getInterval() const noexcept
Get the throttle's configured interval.
bool claim(Clock::time_point now=Clock::now())
Claim the next publication slot, if one is due.