Skip to main content

df_hyperliquid_core/live/
feed.rs

1//! What a socket feed hands back and why it refuses, the same for the native and the browser
2//! feed (`client::native::Feed`, `client::web::Feed`).
3
4use crate::live::{BadFrame, Frame, Refused, Retry};
5
6/// What a feed hands back, in the order it happened.
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub enum Event {
9    /// The socket opened and everything wanted was subscribed again.
10    Opened,
11    /// Boxed: a frame is large and most events are not frames.
12    Frame(Box<Frame>),
13    /// A frame that did not read. The socket is still alive.
14    Unreadable(BadFrame),
15    /// The socket closed, or could not open. The feed dials again after
16    /// `retry.after_ms`; the posts in `retry.unanswered` may or may not have
17    /// landed, so read the account to find out.
18    Closed {
19        /// Why it closed or did not open, as the socket gave it.
20        reason: String,
21        /// When to dial again, and the posts left unanswered.
22        retry: Retry,
23    },
24}
25
26/// Why a feed would not send something, or stopped.
27#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
28pub enum FeedError {
29    /// The session refused it; nothing was sent.
30    #[error(transparent)]
31    Refused(#[from] Refused),
32    /// The feed is gone for good. In the browser this also means the runtime gave no timer
33    /// (no `setTimeout`, or one that threw), so the feed could not keep its time.
34    #[error("the feed has stopped")]
35    Stopped,
36}