Struct Client

Source
pub struct Client { /* private fields */ }
Expand description

A Client manages the underlying WebSocket connection used to talk to Phoenix.

It acts as the primary interface (along with Channel) for working with Phoenix Channels.

When a client is created, it is disconnected, and must be explicitly connected via Self::connect. Once connected, a worker task is spawned that acts as the broker for messages being sent or received over the socket.

Once connected, the more useful Channel instance can be obtained via Self::join. Most functionality related to channels is exposed there.

Implementations§

Source§

impl Client

Source

pub fn new(config: Config) -> Result<Self, ClientError>

Creates a new, disconnected Phoenix Channels client

Source

pub fn config_mut(&mut self) -> &mut Config

Gets a mutable reference to this client’s configuration

Source

pub async fn connect(&mut self) -> Result<(), ClientError>

Connects this client to the configured Phoenix Channels endpoint

This function must be called before using the client to join channels, etc.

A join handle to the socket worker is returned, we can use this to wait until the worker exits to ensure graceful termination. Otherwise, when the handle is dropped, it detaches the worker from the task runtime (though it will continue to run in the background)

Source

pub async fn disconnect(&mut self) -> Result<(), ClientError>

Disconnect the client, regardless of any outstanding channel references

Connected channels will return ChannelError::Closed when next used.

New channels will need to be obtained from this client after connect is called again.

Source

pub fn shutdown(self) -> JoinHandle<Result<(), ClientError>>

Source

pub async fn join( &self, topic: &str, timeout: Option<Duration>, ) -> Result<Arc<Channel>, ChannelError>

Joins topic with optional timeout duration.

If successful, returns a Channel which can be used to interact with the connected channel.

Auto Trait Implementations§

§

impl !Freeze for Client

§

impl RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnwindSafe for Client

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, 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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> ErasedDestructor for T
where T: 'static,