Struct actix_web_actors::ws::WebsocketContext

source ·
pub struct WebsocketContext<A>
where A: Actor<Context = WebsocketContext<A>>,
{ /* private fields */ }
Expand description

Execution context for WebSockets actors

Implementations§

source§

impl<A> WebsocketContext<A>
where A: Actor<Context = Self>,

source

pub fn create<S>( actor: A, stream: S ) -> impl Stream<Item = Result<Bytes, Error>>
where A: StreamHandler<Result<Message, ProtocolError>>, S: Stream<Item = Result<Bytes, PayloadError>> + 'static,

Create a new Websocket context from a request and an actor.

source

pub fn create_with_addr<S>( actor: A, stream: S ) -> (Addr<A>, impl Stream<Item = Result<Bytes, Error>>)
where A: StreamHandler<Result<Message, ProtocolError>>, S: Stream<Item = Result<Bytes, PayloadError>> + 'static,

Create a new Websocket context from a request and an actor.

Returns a pair, where the first item is an addr for the created actor, and the second item is a stream intended to be set as part of the response via [HttpResponseBuilder::streaming()].

source

pub fn with_codec<S>( actor: A, stream: S, codec: Codec ) -> impl Stream<Item = Result<Bytes, Error>>
where A: StreamHandler<Result<Message, ProtocolError>>, S: Stream<Item = Result<Bytes, PayloadError>> + 'static,

Create a new Websocket context from a request, an actor, and a codec

source

pub fn with_factory<S, F>( stream: S, f: F ) -> impl Stream<Item = Result<Bytes, Error>>
where F: FnOnce(&mut Self) -> A + 'static, A: StreamHandler<Result<Message, ProtocolError>>, S: Stream<Item = Result<Bytes, PayloadError>> + 'static,

Create a new Websocket context

source§

impl<A> WebsocketContext<A>
where A: Actor<Context = Self>,

source

pub fn write_raw(&mut self, msg: Message)

Write payload

This is a low-level function that accepts framed messages that should be created using Frame::message(). If you want to send text or binary data you should prefer the text() or binary() convenience functions that handle the framing for you.

source

pub fn text(&mut self, text: impl Into<ByteString>)

Send text frame

source

pub fn binary(&mut self, data: impl Into<Bytes>)

Send binary frame

source

pub fn ping(&mut self, message: &[u8])

Send ping frame

source

pub fn pong(&mut self, message: &[u8])

Send pong frame

source

pub fn close(&mut self, reason: Option<CloseReason>)

Send close frame

source

pub fn handle(&self) -> SpawnHandle

Handle of the running future

SpawnHandle is the handle returned by AsyncContext::spawn() method.

source

pub fn set_mailbox_capacity(&mut self, cap: usize)

Set mailbox capacity

By default mailbox capacity is 16 messages.

Trait Implementations§

source§

impl<A> ActorContext for WebsocketContext<A>
where A: Actor<Context = Self>,

source§

fn stop(&mut self)

Immediately stop processing incoming messages and switch to a stopping state. This only affects actors that are currently running. Future attempts to queue messages will fail.
source§

fn terminate(&mut self)

Terminate actor execution unconditionally. This sets the actor into the stopped state. This causes future attempts to queue messages to fail.
source§

fn state(&self) -> ActorState

Retrieve the current Actor execution state.
source§

impl<A> AsyncContext<A> for WebsocketContext<A>
where A: Actor<Context = Self>,

source§

fn spawn<F>(&mut self, fut: F) -> SpawnHandle
where F: ActorFuture<A, Output = ()> + 'static,

Spawns a future into the context. Read more
source§

fn wait<F>(&mut self, fut: F)
where F: ActorFuture<A, Output = ()> + 'static,

Spawns a future into the context, waiting for it to resolve. Read more
source§

fn cancel_future(&mut self, handle: SpawnHandle) -> bool

Cancels a spawned future. Read more
source§

fn address(&self) -> Addr<A>

Returns the address of the context.
§

fn waiting(&self) -> bool

Checks if the context is paused (waiting for future completion or stopping).
§

fn add_stream<S>(&mut self, fut: S) -> SpawnHandle
where S: Stream + 'static, A: StreamHandler<<S as Stream>::Item>,

Registers a stream with the context. Read more
§

fn add_message_stream<S>(&mut self, fut: S)
where S: Stream + 'static, <S as Stream>::Item: Message, A: Handler<<S as Stream>::Item>,

Registers a stream with the context, ignoring errors. Read more
§

fn notify<M>(&mut self, msg: M)
where A: Handler<M>, M: Message + 'static,

Sends the message msg to self. This bypasses the mailbox capacity, and will always queue the message. If the actor is in the stopped state, an error will be raised.
§

fn notify_later<M>(&mut self, msg: M, after: Duration) -> SpawnHandle
where A: Handler<M>, M: Message + 'static,

Sends the message msg to self after a specified period of time. Read more
§

fn run_later<F>(&mut self, dur: Duration, f: F) -> SpawnHandle
where F: FnOnce(&mut A, &mut <A as Actor>::Context) + 'static,

Executes a closure after a specified period of time. Read more
§

fn run_interval<F>(&mut self, dur: Duration, f: F) -> SpawnHandle
where F: FnMut(&mut A, &mut <A as Actor>::Context) + 'static,

Spawns a job to execute the given closure periodically, at a specified fixed interval.
source§

impl<A> AsyncContextParts<A> for WebsocketContext<A>
where A: Actor<Context = Self>,

source§

fn parts(&mut self) -> &mut ContextParts<A>

source§

impl<A, M> ToEnvelope<A, M> for WebsocketContext<A>
where A: Actor<Context = WebsocketContext<A>> + Handler<M>, M: ActixMessage + Send + 'static, M::Result: Send,

source§

fn pack(msg: M, tx: Option<Sender<M::Result>>) -> Envelope<A>

Pack message into suitable envelope

Auto Trait Implementations§

§

impl<A> Freeze for WebsocketContext<A>

§

impl<A> !RefUnwindSafe for WebsocketContext<A>

§

impl<A> !Send for WebsocketContext<A>

§

impl<A> !Sync for WebsocketContext<A>

§

impl<A> Unpin for WebsocketContext<A>

§

impl<A> !UnwindSafe for WebsocketContext<A>

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more