Skip to content

RequestHandler

veltix.handler.request_handler.RequestHandler

Routes incoming messages, correlates request/response pairs, and dispatches callbacks.

Processing order for each message: 1. Auto-respond to PING with PONG 2. Deliver to pending queue if send_and_wait() is waiting 3. Dispatch to a registered route if one matches 4. Fall back to default on_recv callback 5. Log a warning if nothing handled the message

handle

handle(
    response: Response, client: Optional[ClientInfo] = None
) -> bool

Handle an incoming message with full routing logic.

Parameters:

Name Type Description Default
response Response

The received message.

required
client Optional[ClientInfo]

The sending client (server-side only).

None

Returns:

Type Description
bool

True if the message was handled successfully, False on error.

register

register(request_id: int) -> Queue

Register a pending request BEFORE sending it.

Avoids the race condition where the response arrives before the queue exists.

wait

wait(
    request_id: int, timeout: float = 5.0
) -> Optional[Response]

Wait for a response matching request_id. Must be called after register().

Returns the Response if received within timeout, None otherwise.