Struct actix::WeakRecipient
source · pub struct WeakRecipient<M>{ /* private fields */ }
Expand description
A weakly referenced counterpart to Recipient<M>
Implementations§
source§impl<M> WeakRecipient<M>
impl<M> WeakRecipient<M>
sourcepub fn upgrade(&self) -> Option<Recipient<M>>
pub fn upgrade(&self) -> Option<Recipient<M>>
Attempts to upgrade the WeakRecipient<M>
pointer to an Recipient<M>
, similar to WeakAddr<A>
Examples found in repository?
examples/weak_recipient.rs (line 28)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
fn send_tick(&mut self, _ctx: &mut Context<Self>) {
for client in self.clients.iter() {
if let Some(client) = client.upgrade() {
client.do_send(TimePing(Instant::now()));
println!("⏰ sent ping to client {:?}", client);
} else {
println!("⏰ client can no longer be upgraded");
}
}
// gc
self.clients = self
.clients
.drain(..)
.filter(|c| c.upgrade().is_some())
.collect();
println!("⏰ service has {} clients", self.clients.len());
}
Trait Implementations§
source§impl<M> Clone for WeakRecipient<M>
impl<M> Clone for WeakRecipient<M>
source§impl<M> Debug for WeakRecipient<M>
impl<M> Debug for WeakRecipient<M>
source§impl<A, M: Message + Send + 'static> From<Addr<A>> for WeakRecipient<M>
impl<A, M: Message + Send + 'static> From<Addr<A>> for WeakRecipient<M>
source§fn from(addr: Addr<A>) -> WeakRecipient<M>
fn from(addr: Addr<A>) -> WeakRecipient<M>
Converts to this type from the input type.
source§impl<M> From<Recipient<M>> for WeakRecipient<M>
impl<M> From<Recipient<M>> for WeakRecipient<M>
Auto Trait Implementations§
impl<M> !RefUnwindSafe for WeakRecipient<M>
impl<M> Send for WeakRecipient<M>
impl<M> Sync for WeakRecipient<M>
impl<M> Unpin for WeakRecipient<M>
impl<M> !UnwindSafe for WeakRecipient<M>
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
Mutably borrows from an owned value. Read more