Struct actix_web::ws::WebsocketContext
source · pub struct WebsocketContext<A, S = ()>where
A: Actor<Context = WebsocketContext<A, S>>,{ /* private fields */ }
Expand description
Execution context for WebSockets
actors
Implementations
sourceimpl<A, S: 'static> WebsocketContext<A, S>where
A: Actor<Context = Self>,
impl<A, S: 'static> WebsocketContext<A, S>where
A: Actor<Context = Self>,
sourcepub fn create<P>(req: HttpRequest<S>, actor: A, stream: WsStream<P>) -> Bodywhere
A: StreamHandler<Message, ProtocolError>,
P: Stream<Item = Bytes, Error = PayloadError> + 'static,
pub fn create<P>(req: HttpRequest<S>, actor: A, stream: WsStream<P>) -> Bodywhere
A: StreamHandler<Message, ProtocolError>,
P: Stream<Item = Bytes, Error = PayloadError> + 'static,
Create a new Websocket context from a request and an actor
sourcepub fn with_factory<F>(req: HttpRequest<S>, f: F) -> Bodywhere
F: FnOnce(&mut Self) -> A + 'static,
pub fn with_factory<F>(req: HttpRequest<S>, f: F) -> Bodywhere
F: FnOnce(&mut Self) -> A + 'static,
Create a new Websocket context
sourceimpl<A, S> WebsocketContext<A, S>where
A: Actor<Context = Self>,
impl<A, S> WebsocketContext<A, S>where
A: Actor<Context = Self>,
sourcepub fn write_raw(&mut self, data: FramedMessage)
pub fn write_raw(&mut self, data: FramedMessage)
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 request(&mut self) -> &mut HttpRequest<S>
pub fn request(&mut self) -> &mut HttpRequest<S>
Incoming request
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
sourceimpl<A, S> ActorContext for WebsocketContext<A, S>where
A: Actor<Context = Self>,
impl<A, S> ActorContext for WebsocketContext<A, S>where
A: Actor<Context = Self>,
sourceimpl<A, S> AsyncContext<A> for WebsocketContext<A, S>where
A: Actor<Context = Self>,
impl<A, S> AsyncContext<A> for WebsocketContext<A, S>where
A: Actor<Context = Self>,
sourcefn spawn<F>(&mut self, fut: F) -> SpawnHandlewhere
F: ActorFuture<Item = (), Error = (), Actor = A> + 'static,
fn spawn<F>(&mut self, fut: F) -> SpawnHandlewhere
F: ActorFuture<Item = (), Error = (), Actor = A> + 'static,
Spawn async future into context. Returns handle of the item,
could be used for cancelling execution. Read more
sourcefn wait<F>(&mut self, fut: F)where
F: ActorFuture<Item = (), Error = (), Actor = A> + 'static,
fn wait<F>(&mut self, fut: F)where
F: ActorFuture<Item = (), Error = (), Actor = A> + 'static,
Spawn future into the context. Stop processing any of incoming events
until this future resolves. Read more
sourcefn cancel_future(&mut self, handle: SpawnHandle) -> bool
fn cancel_future(&mut self, handle: SpawnHandle) -> bool
Cancel future. handle is a value returned by
spawn
method.sourcefn waiting(&self) -> bool
fn waiting(&self) -> bool
Check if context is paused (waiting for future completion or stopping)
sourcefn add_stream<S>(&mut self, fut: S) -> SpawnHandlewhere
S: 'static + Stream,
A: StreamHandler<<S as Stream>::Item, <S as Stream>::Error>,
fn add_stream<S>(&mut self, fut: S) -> SpawnHandlewhere
S: 'static + Stream,
A: StreamHandler<<S as Stream>::Item, <S as Stream>::Error>,
This method register stream to an actor context and
allows to handle
Stream
in similar way as normal actor messages. Read moresourcefn add_message_stream<S>(&mut self, fut: S)where
S: 'static + Stream<Error = ()>,
<S as Stream>::Item: Message,
A: Handler<<S as Stream>::Item>,
fn add_message_stream<S>(&mut self, fut: S)where
S: 'static + Stream<Error = ()>,
<S as Stream>::Item: Message,
A: Handler<<S as Stream>::Item>,
This method is similar to
add_stream
but it skips stream errors. Read moresourcefn notify<M>(&mut self, msg: M)where
A: Handler<M>,
M: 'static + Message,
fn notify<M>(&mut self, msg: M)where
A: Handler<M>,
M: 'static + Message,
Send message
msg
to self.sourcefn notify_later<M>(&mut self, msg: M, after: Duration) -> SpawnHandlewhere
A: Handler<M>,
M: 'static + Message,
fn notify_later<M>(&mut self, msg: M, after: Duration) -> SpawnHandlewhere
A: Handler<M>,
M: 'static + Message,
Send message
msg
to self after specified period of time. Returns
spawn handle which could be used for cancellation. Notification get
cancelled if context’s stop method get called. Read moresourcefn run_later<F>(&mut self, dur: Duration, f: F) -> SpawnHandlewhere
F: 'static + FnOnce(&mut A, &mut <A as Actor>::Context),
fn run_later<F>(&mut self, dur: Duration, f: F) -> SpawnHandlewhere
F: 'static + FnOnce(&mut A, &mut <A as Actor>::Context),
Execute closure after specified period of time within same Actor and
Context. Execution get cancelled if context’s stop method get
called. Read more
sourcefn run_interval<F>(&mut self, dur: Duration, f: F) -> SpawnHandlewhere
F: 'static + FnMut(&mut A, &mut <A as Actor>::Context),
fn run_interval<F>(&mut self, dur: Duration, f: F) -> SpawnHandlewhere
F: 'static + FnMut(&mut A, &mut <A as Actor>::Context),
Spawns a job to execute the given closure periodically, at a specified
fixed interval Read more
sourceimpl<A, S> AsyncContextParts<A> for WebsocketContext<A, S>where
A: Actor<Context = Self>,
impl<A, S> AsyncContextParts<A> for WebsocketContext<A, S>where
A: Actor<Context = Self>,
fn parts(&mut self) -> &mut ContextParts<A>
sourceimpl<A, M, S> ToEnvelope<A, M> for WebsocketContext<A, S>where
A: Actor<Context = WebsocketContext<A, S>> + Handler<M>,
M: ActixMessage + Send + 'static,
M::Result: Send,
impl<A, M, S> ToEnvelope<A, M> for WebsocketContext<A, S>where
A: Actor<Context = WebsocketContext<A, S>> + Handler<M>,
M: ActixMessage + Send + 'static,
M::Result: Send,
sourceimpl<A, S> WsWriter for WebsocketContext<A, S>where
A: Actor<Context = Self>,
S: 'static,
impl<A, S> WsWriter for WebsocketContext<A, S>where
A: Actor<Context = Self>,
S: 'static,
sourcefn send_binary<B: Into<Binary>>(&mut self, data: B)
fn send_binary<B: Into<Binary>>(&mut self, data: B)
Send binary frame
sourcefn send_close(&mut self, reason: Option<CloseReason>)
fn send_close(&mut self, reason: Option<CloseReason>)
Send close frame
Auto Trait Implementations
impl<A, S = ()> !RefUnwindSafe for WebsocketContext<A, S>
impl<A, S = ()> !Send for WebsocketContext<A, S>
impl<A, S = ()> !Sync for WebsocketContext<A, S>
impl<A, S> Unpin for WebsocketContext<A, S>
impl<A, S = ()> !UnwindSafe for WebsocketContext<A, S>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more