pub struct WebSocketWithPing { /* private fields */ }Expand description
WebSocket client with automatic ping handling.
Use this when you need automatic keep-alive pings. Call run to process
messages with automatic ping handling.
Implementations§
Source§impl WebSocketWithPing
impl WebSocketWithPing
Sourcepub async fn run<F, Fut>(self, handler: F) -> Result<(), WebSocketError>
pub async fn run<F, Fut>(self, handler: F) -> Result<(), WebSocketError>
Run the WebSocket message loop with automatic ping handling.
This method will:
- Send ping messages at the configured interval
- Call the provided handler for each received message
- Return when the connection is closed or an error occurs
§Arguments
handler- Async function called for each received channel message
§Example
use polyte_clob::ws::{WebSocketBuilder, Channel};
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let ws = WebSocketBuilder::new()
.ping_interval(Duration::from_secs(10))
.connect_market(vec!["asset_id".to_string()])
.await?;
ws.run(|msg| async move {
println!("Received: {:?}", msg);
Ok(())
}).await?;
Ok(())
}Sourcepub fn channel_type(&self) -> ChannelType
pub fn channel_type(&self) -> ChannelType
Get the channel type this WebSocket is connected to.
Auto Trait Implementations§
impl !Freeze for WebSocketWithPing
impl !RefUnwindSafe for WebSocketWithPing
impl Send for WebSocketWithPing
impl Sync for WebSocketWithPing
impl Unpin for WebSocketWithPing
impl !UnwindSafe for WebSocketWithPing
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more