|
Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
|
Correlates an in-flight HTTP request with its execution report. More...
#include <order_gateway/pending_responses.hpp>
Public Types | |
| using | Id = uint64_t |
| using | Completion = std::function<void(const OrderResponse*)> |
| Invoked with the matching report, or with nullptr when the wait timed out. | |
| using | Predicate = std::function<bool(const OrderResponse&)> |
Public Member Functions | |
| Id | add (Predicate matches, Completion complete) |
| bool | dispatch (const OrderResponse &response) |
| Offers a report to the waiters, completing at most one of them. | |
| void | expire (Id id) |
| Completes a waiter as timed out. | |
| void | abandon (Id id) |
| Drops a waiter without completing it, for a client that went away. | |
| bool | waiting (Id id) const |
| size_t | size () const noexcept |
Static Public Attributes | |
| static constexpr Id | kNoId = 0 |
Correlates an in-flight HTTP request with its execution report.
A handler records what it is waiting for and returns. The gateway's drain completes the response when a report arrives; the request timer completes it on timeout. Polling with a 100us sleep would block the gateway's only event loop for the full timeout, once per entry for a batch request.
Predicates support the handlers' different correlation keys: client_order_id for creates and request timestamps for cancels. The list is bounded by the requests in flight, so scanning costs less than maintaining several indexes.
All methods run on the gateway's loop thread.
Definition at line 23 of file pending_responses.hpp.
| using slick::sim::order_gateway::PendingResponses::Completion = std::function<void(const OrderResponse*)> |
Invoked with the matching report, or with nullptr when the wait timed out.
Called exactly once per waiter unless the waiter is abandoned.
Definition at line 28 of file pending_responses.hpp.
| using slick::sim::order_gateway::PendingResponses::Id = uint64_t |
Definition at line 25 of file pending_responses.hpp.
| using slick::sim::order_gateway::PendingResponses::Predicate = std::function<bool(const OrderResponse&)> |
Definition at line 29 of file pending_responses.hpp.
|
inline |
Drops a waiter without completing it, for a client that went away.
The completion is never run, because it would write to a dead connection.
Definition at line 72 of file pending_responses.hpp.
|
inline |
Definition at line 33 of file pending_responses.hpp.
|
inline |
Offers a report to the waiters, completing at most one of them.
A report answers a single request, so the first match wins and the rest keep waiting. Returns whether anything claimed it.
Definition at line 43 of file pending_responses.hpp.
|
inline |
Completes a waiter as timed out.
A no-op if its report already arrived, so a timer that fires after the fact is harmless.
Definition at line 60 of file pending_responses.hpp.
|
inlinenoexcept |
Definition at line 88 of file pending_responses.hpp.
|
inline |
Definition at line 79 of file pending_responses.hpp.
|
staticconstexpr |
Definition at line 31 of file pending_responses.hpp.