34 const Id id = ++next_id_;
35 waiters_.push_back({id, std::move(matches), std::move(complete)});
44 for (
auto it = waiters_.begin(); it != waiters_.end(); ++it) {
45 if (!it->matches(response)) {
62 if (it == waiters_.end()) {
74 if (it != waiters_.end()) {
80 for (
const auto &waiter : waiters_) {
81 if (waiter.id ==
id) {
88 size_t size() const noexcept {
return waiters_.size(); }
97 std::vector<Waiter>::iterator find(
Id id) {
98 for (
auto it = waiters_.begin(); it != waiters_.end(); ++it) {
103 return waiters_.end();
106 std::vector<Waiter> waiters_;
Correlates an in-flight HTTP request with its execution report.
std::function< void(const OrderResponse *)> Completion
Invoked with the matching report, or with nullptr when the wait timed out.
static constexpr Id kNoId
void expire(Id id)
Completes a waiter as timed out.
bool dispatch(const OrderResponse &response)
Offers a report to the waiters, completing at most one of them.
size_t size() const noexcept
bool waiting(Id id) const
std::function< bool(const OrderResponse &)> Predicate
void abandon(Id id)
Drops a waiter without completing it, for a client that went away.
Id add(Predicate matches, Completion complete)