pub struct Connection { /* private fields */ }Expand description
Manages a WebSocket connection to the Titan API with auto-reconnect.
Implementations§
Source§impl Connection
impl Connection
Sourcepub async fn connect(config: TitanConfig) -> Result<Self, TitanClientError>
pub async fn connect(config: TitanConfig) -> Result<Self, TitanClientError>
Create a new connection with the given config.
Connects eagerly and auto-reconnects on disconnection.
Sourcepub async fn send_request(
&self,
data: RequestData,
) -> Result<ResponseSuccess, TitanClientError>
pub async fn send_request( &self, data: RequestData, ) -> Result<ResponseSuccess, TitanClientError>
Send a request and wait for response.
Sourcepub async fn register_stream(
&self,
stream_id: u32,
request: SwapQuoteRequest,
sender: Sender<StreamData>,
on_end: Option<Arc<dyn Fn() + Send + Sync>>,
effective_id: Option<Arc<AtomicU32>>,
stopped: Arc<AtomicBool>,
)
pub async fn register_stream( &self, stream_id: u32, request: SwapQuoteRequest, sender: Sender<StreamData>, on_end: Option<Arc<dyn Fn() + Send + Sync>>, effective_id: Option<Arc<AtomicU32>>, stopped: Arc<AtomicBool>, )
Register a resumable stream.
Sourcepub async fn unregister_stream(&self, stream_id: u32)
pub async fn unregister_stream(&self, stream_id: u32)
Unregister a stream.
Sourcepub fn state_receiver(&self) -> Receiver<ConnectionState>
pub fn state_receiver(&self) -> Receiver<ConnectionState>
Get a receiver for connection state changes.
Sourcepub fn state(&self) -> ConnectionState
pub fn state(&self) -> ConnectionState
Get the current connection state.
Sourcepub async fn active_stream_ids(&self) -> Vec<u32>
pub async fn active_stream_ids(&self) -> Vec<u32>
Get all active stream IDs.
Sourcepub async fn stop_all_streams(&self)
pub async fn stop_all_streams(&self)
Stop all active streams gracefully.
Sends StopStream for each active stream and clears the stream map.
Auto Trait Implementations§
impl !Freeze for Connection
impl !RefUnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl !UnwindSafe for Connection
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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