22#include "util/async/AnyStrand.hpp"
38template <
typename T,
typename Compare = std::less<T>>
42 std::priority_queue<T, std::vector<T>, Compare> queue_;
51 : strand_(std::move(strand)), limit_(limit.value_or(0uz))
66 requires std::is_same_v<std::decay_t<I>, T>
70 if (limit_ == 0uz or queue_.size() < limit_) {
71 queue_.push(std::forward<I>(item));
85 [[nodiscard]] std::optional<T>
89 .
execute([
this] -> std::optional<T> {
92 if (not queue_.empty()) {
93 out.emplace(queue_.top());
100 .value_or(std::nullopt);
112 return strand_.
execute([
this] {
return queue_.empty(); }).get().value();
A wrapper for std::priority_queue that serialises operations using a strand.
Definition StrandedPriorityQueue.hpp:39
StrandedPriorityQueue(util::async::AnyStrand &&strand, std::optional< std::size_t > limit=std::nullopt)
Construct a new priority queue on a strand.
Definition StrandedPriorityQueue.hpp:50
bool empty()
Check if the queue is empty.
Definition StrandedPriorityQueue.hpp:110
bool enqueue(I &&item)
Enqueue a new item onto the queue if space is available.
Definition StrandedPriorityQueue.hpp:65
std::optional< T > dequeue()
Dequeue the next available item out of the queue.
Definition StrandedPriorityQueue.hpp:86
A type-erased execution context.
Definition AnyStrand.hpp:40
auto execute(SomeHandlerWithoutStopToken auto &&fn)
Execute a function without a stop token on the strand.
Definition AnyStrand.hpp:65
This namespace contains various utilities.
Definition AccountUtils.hpp:30