5#include <unordered_map>
6#include <unordered_set>
14template<
typename Work,
typename Key = std::
int64_t>
27 if (m_outstanding.insert_or_assign(key, std::move(work)).second)
29 m_order.push_back(key);
40 m_outstanding.erase(key);
41 m_dispatched.erase(key);
57 m_dispatched.erase(key);
67 template<
typename DispatchFn>
70 int dispatchedCount = 0;
73 for (std::size_t i = 0; i < m_order.size(); ++i)
75 const Key& key = m_order[i];
76 const auto entry = m_outstanding.find(key);
77 if (entry != m_outstanding.end())
79 m_order[live++] = key;
80 if (!stopped && !m_dispatched.contains(key))
82 if (dispatch(key, entry->second))
84 m_dispatched.insert(key);
95 return dispatchedCount;
98 [[nodiscard]] std::size_t
size() const noexcept
100 return m_outstanding.size();
105 return m_dispatched.contains(key);
109 std::unordered_map<Key, Work> m_outstanding;
110 std::unordered_set<Key> m_dispatched;
111 std::vector<Key> m_order;
Definition OutstandingWork.hpp:16
void onNotLeader()
Definition OutstandingWork.hpp:45
void onReply(const Key &key)
Records a request's sequenced reply, on every replica: the request is answered.
Definition OutstandingWork.hpp:38
void onReplyNotEmitted(const Key &key)
Records that a reply offer failed, so no sequenced reply will come.
Definition OutstandingWork.hpp:55
std::size_t size() const noexcept
Definition OutstandingWork.hpp:98
bool isDispatched(const Key &key) const
Definition OutstandingWork.hpp:103
void onRequest(const Key &key, Work work)
Records a request seen on the sequenced stream, on every replica.
Definition OutstandingWork.hpp:25
int dispatchUndispatched(DispatchFn &&dispatch)
Offers each undispatched outstanding request, in request order.
Definition OutstandingWork.hpp:68
Definition ClusterError.hpp:5