Skip to main content

ClientState

Struct ClientState 

Source
pub struct ClientState {
    pub url: String,
    /* private fields */
}
Expand description

Handle to one per-connection state. The state itself lives on the client store’s owner thread; a handle carries only the key (url) and the wakeup channel its waiters await.

Fields§

§url: String

Implementations§

Source§

impl ClientState

Source

pub async fn next_message(&self) -> Option<Value>

Await the next inbound message. None once the socket is closed and the backlog is drained. The waiter is armed before the queue is read, so a resolve/push racing the await is never lost.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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 in the same store job as the check — TS’s documented “atomic check-and-insert”.

Source

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.

Source

pub fn flight_is_open(&self, hash: &str) -> bool

Whether a flight for hash exists and is still open.

Source

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.

Source

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.

Source

pub fn set_subscription(&self, subscribe_hash: &str, subscription: Value)

Directly set a subscription entry (TS client.subscriptions[h] = x written from handle_message).

Source

pub fn is_subscribed(&self, subscribe_hash: &str) -> bool

Source

pub fn send_text(&self, s: String) -> bool

Source

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.

Source

pub fn mock_inject(&self, msg: Value)

Injected inbound frame → the same queue the socket reader feeds.

Source

pub fn is_mock(&self) -> bool

Source

pub fn mock_sent_value(&self) -> Value

The captured outgoing frames as a Value::List.

Source

pub fn has_pending_futures(&self) -> bool

Source

pub fn has_queued_messages(&self) -> bool

Whether the mock inbound queue still holds un-consumed frames.

Source

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).

Source

pub fn mark_ws_test_completed(&self)

Source

pub fn is_ws_test_completed(&self) -> bool

Source

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.

Source

pub fn is_closed(&self) -> bool

Source

pub fn is_connected(&self) -> bool

Source

pub fn on_pong(&self)

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn futures_value(&self) -> Value

Snapshot of futures as a Value::Map { hash: true }.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more