Skip to main content

Session

Struct Session 

Source
pub struct Session<T> { /* private fields */ }
Expand description

A sequential, runtime-neutral Phoenix Channels session.

Session owns a transport and preserves server events that arrive while a join, push, leave, or heartbeat reply is being awaited. Applications that need commands from multiple tasks should own the session in one task and communicate with it over their executor’s channel type.

Implementations§

Source§

impl<T: Transport> Session<T>

Source

pub fn new(transport: T) -> Self

Creates a session using the bounded default Phoenix v2 codec.

Source

pub fn with_codec(transport: T, codec: impl Codec + 'static) -> Self

Creates a session with an application-provided codec.

Source

pub fn protocol(&self) -> &Protocol

Borrows the session’s protocol state.

Source

pub fn protocol_mut(&mut self) -> &mut Protocol

Mutably borrows the session’s protocol state.

Source

pub fn transport_mut(&mut self) -> &mut T

Mutably borrows the underlying transport.

Source

pub fn into_parts(self) -> (Protocol, T)

Consumes the session and returns its protocol and transport.

Source

pub async fn join( &mut self, topic: impl Into<String>, params: Value, ) -> Result<ProtocolEvent, SessionError>

Sends a join and waits for its correlated reply.

Source

pub async fn rejoin( &mut self, topic: impl Into<String>, refreshed_params: Value, ) -> Result<ProtocolEvent, SessionError>

Sends a rejoin with refreshed parameters and waits for its reply.

Source

pub async fn push( &mut self, topic: &str, event: impl Into<String>, payload: impl Into<Payload>, ) -> Result<ProtocolEvent, SessionError>

Sends an application event and waits for its correlated reply.

Source

pub async fn leave( &mut self, topic: &str, ) -> Result<ProtocolEvent, SessionError>

Leaves a joined topic and waits for its reply.

Source

pub async fn heartbeat(&mut self) -> Result<ProtocolEvent, SessionError>

Sends a Phoenix heartbeat and waits for its acknowledgement.

Source

pub async fn next_event(&mut self) -> Result<ProtocolEvent, SessionError>

Returns the next buffered or transport event.

Source

pub fn reset_connection(&mut self) -> Vec<ProtocolEvent>

Marks all channels disconnected and returns the requests interrupted by transport loss. The caller can then reconnect a transport and call rejoin with refreshed authentication parameters.

Source

pub async fn close(&mut self) -> Result<(), SessionError>

Closes the underlying transport.

Auto Trait Implementations§

§

impl<T> Freeze for Session<T>
where T: Freeze,

§

impl<T> !RefUnwindSafe for Session<T>

§

impl<T> !Send for Session<T>

§

impl<T> !Sync for Session<T>

§

impl<T> Unpin for Session<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Session<T>
where T: UnsafeUnpin,

§

impl<T> !UnwindSafe for Session<T>

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