pub struct ChannelContext {
pub identifier: String,
/* private fields */
}Expand description
Per-subscription context handed to a Channel’s lifecycle callbacks. It
carries the ActionCable identifier, an outbound sink to this connection,
and the pub/sub backend, so a channel can transmit, stream_from, read
params, and stop_all_streams (Rails ActionCable::Channel).
Fields§
§identifier: StringThe raw ActionCable subscription identifier (a JSON string).
Implementations§
Source§impl ChannelContext
impl ChannelContext
Sourcepub fn for_test(
identifier: impl Into<String>,
) -> (Self, UnboundedReceiver<String>)
pub fn for_test( identifier: impl Into<String>, ) -> (Self, UnboundedReceiver<String>)
A context wired to a fresh channel and in-memory pub/sub, returning the
receiving end so tests can observe transmit/stream_from output.
Sourcepub fn params(&self) -> Value
pub fn params(&self) -> Value
The subscription params: the parsed ActionCable identifier JSON (e.g.
{ "channel": "ChatChannel", "room": "42" }), or Null if unparseable.
Sourcepub fn transmit(&self, message: Value)
pub fn transmit(&self, message: Value)
Send a message to just this connection (Rails transmit). Wrapped as an
ActionCable ServerMessage carrying this subscription’s identifier.
Sourcepub async fn stream_from(&self, stream: &str)
pub async fn stream_from(&self, stream: &str)
Subscribe this connection to stream: anything published to it (e.g. via
Cable::broadcast) is forwarded to the client (Rails stream_from).
Sourcepub async fn stop_all_streams(&self)
pub async fn stop_all_streams(&self)
Stop forwarding every stream this connection subscribed to (Rails
stop_all_streams).
Auto Trait Implementations§
impl !RefUnwindSafe for ChannelContext
impl !UnwindSafe for ChannelContext
impl Freeze for ChannelContext
impl Send for ChannelContext
impl Sync for ChannelContext
impl Unpin for ChannelContext
impl UnsafeUnpin for ChannelContext
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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>
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>
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