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>,
impl<A> WebsocketContext<A>where
A: Actor<Context = Self>,
sourcepub 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,
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.
sourcepub 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,
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()
].
sourcepub 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,
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
sourcepub fn with_factory<S, F>(
stream: S,
f: F
) -> impl Stream<Item = Result<Bytes, Error>>
pub fn with_factory<S, F>( stream: S, f: F ) -> impl Stream<Item = Result<Bytes, Error>>
Create a new Websocket context
source§impl<A> WebsocketContext<A>where
A: Actor<Context = Self>,
impl<A> WebsocketContext<A>where
A: Actor<Context = Self>,
sourcepub fn write_raw(&mut self, msg: Message)
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.
sourcepub fn close(&mut self, reason: Option<CloseReason>)
pub fn close(&mut self, reason: Option<CloseReason>)
Send close frame
sourcepub fn handle(&self) -> SpawnHandle
pub fn handle(&self) -> SpawnHandle
Handle of the running future
SpawnHandle is the handle returned by AsyncContext::spawn()
method.
sourcepub fn set_mailbox_capacity(&mut self, cap: usize)
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>,
impl<A> ActorContext for WebsocketContext<A>where
A: Actor<Context = Self>,
source§fn stop(&mut self)
fn stop(&mut self)
stopping
state. This only affects actors that are currently
running
. Future attempts to queue messages will fail.source§impl<A> AsyncContext<A> for WebsocketContext<A>where
A: Actor<Context = Self>,
impl<A> AsyncContext<A> for WebsocketContext<A>where
A: Actor<Context = Self>,
source§fn spawn<F>(&mut self, fut: F) -> SpawnHandlewhere
F: ActorFuture<A, Output = ()> + 'static,
fn spawn<F>(&mut self, fut: F) -> SpawnHandlewhere
F: ActorFuture<A, Output = ()> + 'static,
source§fn wait<F>(&mut self, fut: F)where
F: ActorFuture<A, Output = ()> + 'static,
fn wait<F>(&mut self, fut: F)where
F: ActorFuture<A, Output = ()> + 'static,
source§fn cancel_future(&mut self, handle: SpawnHandle) -> bool
fn cancel_future(&mut self, handle: SpawnHandle) -> bool
§fn waiting(&self) -> bool
fn waiting(&self) -> bool
§fn add_stream<S>(&mut self, fut: S) -> SpawnHandlewhere
S: Stream + 'static,
A: StreamHandler<<S as Stream>::Item>,
fn add_stream<S>(&mut self, fut: S) -> SpawnHandlewhere
S: Stream + 'static,
A: StreamHandler<<S as Stream>::Item>,
§fn add_message_stream<S>(&mut self, fut: S)where
S: Stream + 'static,
<S as Stream>::Item: Message,
A: Handler<<S as Stream>::Item>,
fn add_message_stream<S>(&mut self, fut: S)where
S: Stream + 'static,
<S as Stream>::Item: Message,
A: Handler<<S as Stream>::Item>,
§fn notify<M>(&mut self, msg: M)where
A: Handler<M>,
M: Message + 'static,
fn notify<M>(&mut self, msg: M)where
A: Handler<M>,
M: Message + 'static,
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) -> SpawnHandlewhere
A: Handler<M>,
M: Message + 'static,
fn notify_later<M>(&mut self, msg: M, after: Duration) -> SpawnHandlewhere
A: Handler<M>,
M: Message + 'static,
msg
to self after a specified period of time. Read more