pub struct ClientState {
pub url: String,
/* private fields */
}Expand description
Per-connection state. Lives in [REGISTRY] behind an Arc, so both the
background reader/writer tasks and the watch drive loop share it.
Fields§
§url: StringImplementations§
Source§impl ClientState
impl ClientState
Sourcepub async fn next_message(&self) -> Option<Value>
pub async fn next_message(&self) -> Option<Value>
Await the next inbound message. None once the socket is closed and
the backlog is drained. Uses the create-future-before-check pattern so
a resolve/push racing the await is never lost.
Sourcepub fn resolve(&self, hash: &str, value: Value)
pub fn resolve(&self, hash: &str, value: Value)
Store a resolved value for hash (TS client.resolve). Also settles an
open single-flight on the same hash: TS’s client.resolve () settles
the future AND removes it from client.futures, which is what lets the
next cycle elect a fresh leader. Both paths run — a hash can in
principle be someone’s flight and someone else’s watch, and only the
waiter that exists will read its side.
Sourcepub fn reject(&self, hash: &str, err: Value)
pub fn reject(&self, hash: &str, err: Value)
Store an error for hash (TS client.reject), settling an open
single-flight on the same hash — see resolve.
Sourcepub fn take_settled(&self, hashes: &[String]) -> Option<Result<Value, Value>>
pub fn take_settled(&self, hashes: &[String]) -> Option<Result<Value, Value>>
If any of hashes has a resolved value or rejection, remove and return
it (Ok for value, Err for rejection). Rejections take priority.
Sourcepub fn note_futures(&self, hashes: &[String])
pub fn note_futures(&self, hashes: &[String])
Register interest in hashes (TS client.future). Returns true if the
subscribe frame still needs sending for subscribe_hash.
Sourcepub fn flight_begin(&self, hash: &str) -> bool
pub fn flight_begin(&self, hash: &str) -> bool
Open a single-flight for hash, or join one already in progress. true
means this caller is the leader and must do the work; false means a
flight is already open and the caller should wait on it.
The insert into futures is what makes the transpiled
if (messageHash in client.futures) follower test observable, and it
happens under the same lock as the check — this is TS’s documented
“atomic check-and-insert”.
Sourcepub fn flight_peek(&self, hash: &str) -> Option<Result<Value, Value>>
pub fn flight_peek(&self, hash: &str) -> Option<Result<Value, Value>>
The flight’s last outcome, if it has one. Does NOT consume it: every waiter must be able to observe the same result.
Sourcepub fn flight_is_open(&self, hash: &str) -> bool
pub fn flight_is_open(&self, hash: &str) -> bool
Whether a flight for hash exists and is still open.
Sourcepub fn flight_settle(&self, hash: &str, res: Result<Value, Value>) -> bool
pub fn flight_settle(&self, hash: &str, res: Result<Value, Value>) -> bool
Settle an open flight and wake its waiters. Returns false (and does
nothing) when hash names no open flight, so resolve/reject can
fall through to their normal watch-hash behaviour.
Sourcepub fn subscribe_once(&self, subscribe_hash: &str, subscription: Value) -> bool
pub fn subscribe_once(&self, subscribe_hash: &str, subscription: Value) -> bool
Record subscribe_hash → subscription; returns true the first time
(so the caller sends the subscribe frame exactly once). Mirrors TS
client.subscriptions[subscribeHash] = subscription || true.
Sourcepub fn set_subscription(&self, subscribe_hash: &str, subscription: Value)
pub fn set_subscription(&self, subscribe_hash: &str, subscription: Value)
Directly set a subscription entry (TS client.subscriptions[h] = x
written from handle_message).
pub fn is_subscribed(&self, subscribe_hash: &str) -> bool
pub fn send_text(&self, s: String) -> bool
Sourcepub fn mock_enable(&self)
pub fn mock_enable(&self)
Enable the mock transport: mark connected (so ensure_client never opens
a socket) and route send_text to the capture buffer.
Sourcepub fn mock_inject(&self, msg: Value)
pub fn mock_inject(&self, msg: Value)
Injected inbound frame → the same queue the socket reader feeds.
pub fn is_mock(&self) -> bool
Sourcepub fn mock_sent_value(&self) -> Value
pub fn mock_sent_value(&self) -> Value
The captured outgoing frames as a Value::List.
pub fn has_pending_futures(&self) -> bool
Sourcepub fn has_queued_messages(&self) -> bool
pub fn has_queued_messages(&self) -> bool
Whether the mock inbound queue still holds un-consumed frames.
Sourcepub fn pop_queued_message(&self) -> Option<Value>
pub fn pop_queued_message(&self) -> Option<Value>
Pop the oldest un-consumed inbound frame (static-WS harness: replay the acks an unWatch* fixture holds beyond the one that resolved the call).
pub fn mark_ws_test_completed(&self)
pub fn is_ws_test_completed(&self) -> bool
Sourcepub fn reject_pending_futures(&self, err: Value)
pub fn reject_pending_futures(&self, err: Value)
Reject every pending future so a fixture whose frames don’t resolve the watch fails (with a message) rather than hanging the drive loop.
pub fn is_closed(&self) -> bool
pub fn on_pong(&self)
Sourcepub fn reset(&self)
pub fn reset(&self)
Drop resolved/rejected/subscription/future state,
e.g. after a reconnect so stale hashes don’t resolve new waiters.
Internal wipe only — the transpiled client.reset(error) goes through
reset_with_error below, which delivers the error first.
Sourcepub fn reset_with_error(&self, error: Value)
pub fn reset_with_error(&self, error: Value)
TS client.reset(error) — reject every pending future/flight with the
error so waiters fail fast instead of hanging, then drop the pending
future state. Mirrors the js/php/c#/go/java/python clients: rejections
are kept (they carry the error to the waiters), delivered-but-not-taken
resolved values are kept (in TS an already-resolved future is settled
— reject on it is a no-op — so its waiter still gets the value), and
subscriptions are left to the caller — the TS Client.reset does not
clear them either.
Sourcepub fn subscriptions_value(&self) -> Value
pub fn subscriptions_value(&self) -> Value
Snapshot of subscriptions as a Value::Map { hash: subscription } —
the shape the transpiled get_value(&client, "subscriptions") reads.
Tagged with __ws_subs_url so that writes performed on the snapshot
(client.subscriptions[chanId] = …, common in bitfinex/chan-id venues)
route back to this live ClientState instead of a discarded clone.
Sourcepub fn set_subscription_field(&self, hash: &str, key: &str, val: Value)
pub fn set_subscription_field(&self, hash: &str, key: &str, val: Value)
Set a field on a stored subscription dict (client.subscriptions[hash] [key] = val). Creates the entry if missing.
Sourcepub fn futures_value(&self) -> Value
pub fn futures_value(&self) -> Value
Snapshot of futures as a Value::Map { hash: true }.