[−][src]Struct kompact::prelude::ActorRefStrong
A version of ActorRef that prevents the target from being deallocated
Holding this kind of reference increases performance slightly, compared to the normal ActorRef. However, one must be careful not to leave strong references lying around when not needed anymore, as they prevent the target component from being deallocated, potentially causing memory creep.
Should be created via hold.
It is recommended to upgrade a normal actor reference to this variant, if many messages will be sent in a loop to it. After the loop, the strong reference can be dropped again.
Methods
impl<M: MessageBounds> ActorRefStrong<M>
[src]
pub fn tell<I>(&self, v: I) where
I: Into<M>,
[src]
I: Into<M>,
Send message v
to the actor instance referenced by this actor reference
pub fn ask<R, F>(&self, f: F) -> Future<R> where
R: Send + Sized,
F: FnOnce(Promise<R>) -> M,
[src]
R: Send + Sized,
F: FnOnce(Promise<R>) -> M,
Helper to create messages that expect a response via a future instead of a message
Example
use kompact::prelude::*; use std::time::Duration; #[derive(ComponentDefinition)] struct AskComponent { ctx: ComponentContext<Self> } impl Actor for AskComponent { type Message = Ask<u64, String>; fn receive_local(&mut self, msg: Self::Message) -> () { msg.complete(|num| { format!("{}", num) }) .expect("completion"); } } let system = KompactConfig::default().build().expect("system"); let c = system.create(AskComponent::new); let strong_ref = c.actor_ref().hold().expect("live ref"); let start_f = system.start_notify(&c); start_f .wait_timeout(Duration::from_millis(1000)) .expect("component start"); let response_f = strong_ref.ask(Ask::of(42u64)); let response = response_f .wait_timeout(Duration::from_millis(1000)) .expect("response"); assert_eq!("42".to_string(), response);
pub fn weak_ref(&self) -> ActorRef<M>
[src]
Downgrade this strong reference to a "normal" actor reference
Trait Implementations
impl<M: MessageBounds> ActorRefFactory for ActorRefStrong<M>
[src]
type Message = M
The type of messages carried by references produced by this factory
fn actor_ref(&self) -> ActorRef<M>
[src]
impl<M: MessageBounds> Clone for ActorRefStrong<M>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<M: MessageBounds> Debug for ActorRefStrong<M>
[src]
impl<M: MessageBounds> Display for ActorRefStrong<M>
[src]
impl<M: MessageBounds> PartialEq<ActorRefStrong<M>> for ActorRefStrong<M>
[src]
fn eq(&self, other: &ActorRefStrong<M>) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl Sink for ActorRefStrong<DispatchEnvelope>
[src]
Helper for forwarding MsgEnvelopes to actor references
type SinkError = ()
The type of value produced by the sink when an error occurs.
type SinkItem = DispatchEnvelope
The type of value that the sink accepts.
fn start_send(
&mut self,
item: Self::SinkItem
) -> StartSend<Self::SinkItem, Self::SinkError>
[src]
&mut self,
item: Self::SinkItem
) -> StartSend<Self::SinkItem, Self::SinkError>
fn poll_complete(&mut self) -> Poll<(), Self::SinkError>
[src]
fn close(&mut self) -> Poll<(), Self::SinkError>
[src]
fn wait(self) -> Wait<Self>
[src]
fn with<U, F, Fut>(self, f: F) -> With<Self, U, F, Fut> where
F: FnMut(U) -> Fut,
Fut: IntoFuture<Item = Self::SinkItem>,
<Fut as IntoFuture>::Error: From<Self::SinkError>,
[src]
F: FnMut(U) -> Fut,
Fut: IntoFuture<Item = Self::SinkItem>,
<Fut as IntoFuture>::Error: From<Self::SinkError>,
fn with_flat_map<U, F, St>(self, f: F) -> WithFlatMap<Self, U, F, St> where
F: FnMut(U) -> St,
St: Stream<Item = Self::SinkItem, Error = Self::SinkError>,
[src]
F: FnMut(U) -> St,
St: Stream<Item = Self::SinkItem, Error = Self::SinkError>,
fn sink_map_err<F, E>(self, f: F) -> SinkMapErr<Self, F> where
F: FnOnce(Self::SinkError) -> E,
[src]
F: FnOnce(Self::SinkError) -> E,
fn sink_from_err<E>(self) -> SinkFromErr<Self, E> where
E: From<Self::SinkError>,
[src]
E: From<Self::SinkError>,
fn buffer(self, amt: usize) -> Buffer<Self>
[src]
fn fanout<S>(self, other: S) -> Fanout<Self, S> where
S: Sink<SinkItem = Self::SinkItem, SinkError = Self::SinkError>,
Self::SinkItem: Clone,
[src]
S: Sink<SinkItem = Self::SinkItem, SinkError = Self::SinkError>,
Self::SinkItem: Clone,
fn flush(self) -> Flush<Self>
[src]
fn send(self, item: Self::SinkItem) -> Send<Self>
[src]
fn send_all<S>(self, stream: S) -> SendAll<Self, S> where
S: Stream<Item = Self::SinkItem>,
Self::SinkError: From<<S as Stream>::Error>,
[src]
S: Stream<Item = Self::SinkItem>,
Self::SinkError: From<<S as Stream>::Error>,
Auto Trait Implementations
impl<M> !RefUnwindSafe for ActorRefStrong<M>
impl<M> Send for ActorRefStrong<M>
impl<M> Sync for ActorRefStrong<M>
impl<M> Unpin for ActorRefStrong<M>
impl<M> !UnwindSafe for ActorRefStrong<M>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,