Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
Loading...
Searching...
No Matches
slick::sim::order_gateway::PendingResponses Class Reference

Correlates an in-flight HTTP request with its execution report. More...

#include <order_gateway/pending_responses.hpp>

Collaboration diagram for slick::sim::order_gateway::PendingResponses:

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

Detailed Description

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.

Member Typedef Documentation

◆ Completion

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.

◆ Id

Definition at line 25 of file pending_responses.hpp.

◆ Predicate

Definition at line 29 of file pending_responses.hpp.

Member Function Documentation

◆ abandon()

void slick::sim::order_gateway::PendingResponses::abandon ( Id id)
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.

◆ add()

Id slick::sim::order_gateway::PendingResponses::add ( Predicate matches,
Completion complete )
inline

Definition at line 33 of file pending_responses.hpp.

◆ dispatch()

bool slick::sim::order_gateway::PendingResponses::dispatch ( const OrderResponse & response)
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.

◆ expire()

void slick::sim::order_gateway::PendingResponses::expire ( Id id)
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.

◆ size()

size_t slick::sim::order_gateway::PendingResponses::size ( ) const
inlinenoexcept

Definition at line 88 of file pending_responses.hpp.

◆ waiting()

bool slick::sim::order_gateway::PendingResponses::waiting ( Id id) const
inline

Definition at line 79 of file pending_responses.hpp.

Member Data Documentation

◆ kNoId

Id slick::sim::order_gateway::PendingResponses::kNoId = 0
staticconstexpr

Definition at line 31 of file pending_responses.hpp.


The documentation for this class was generated from the following file: