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>>where
F: FnOnce(&mut Self) -> A + 'static,
A: StreamHandler<Result<Message, ProtocolError>>,
S: Stream<Item = Result<Bytes, PayloadError>> + 'static,
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>,
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 text(&mut self, text: impl Into<ByteString>)
pub fn text(&mut self, text: impl Into<ByteString>)
Send text frame
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§fn terminate(&mut self)
fn terminate(&mut self)
stopped
state. This causes future attempts to queue
messages to fail.Source§fn state(&self) -> ActorState
fn state(&self) -> ActorState
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
Source§fn waiting(&self) -> bool
fn waiting(&self) -> bool
Source§fn add_stream<S>(&mut self, fut: S) -> SpawnHandle
fn add_stream<S>(&mut self, fut: S) -> SpawnHandle
Source§fn add_message_stream<S>(&mut self, fut: S)
fn add_message_stream<S>(&mut self, fut: S)
Source§fn notify<M>(&mut self, msg: M)
fn notify<M>(&mut self, msg: M)
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.Source§fn notify_later<M>(&mut self, msg: M, after: Duration) -> SpawnHandle
fn notify_later<M>(&mut self, msg: M, after: Duration) -> SpawnHandle
msg
to self after a specified period of time. Read moreSource§fn run_later<F>(&mut self, dur: Duration, f: F) -> SpawnHandle
fn run_later<F>(&mut self, dur: Duration, f: F) -> SpawnHandle
Source§fn run_interval<F>(&mut self, dur: Duration, f: F) -> SpawnHandle
fn run_interval<F>(&mut self, dur: Duration, f: F) -> SpawnHandle
Source§fn run_interval_at<F>(
&mut self,
start: Instant,
interval: Duration,
task: F,
) -> SpawnHandle
fn run_interval_at<F>( &mut self, start: Instant, interval: Duration, task: F, ) -> SpawnHandle
task
function to begin executing at the given start
time, and with the
given interval
duration.