[][src]Struct kompact::prelude::ActorRefStrong

pub struct ActorRefStrong<M: MessageBounds> { /* fields omitted */ }

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]

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]

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

impl<M: MessageBounds> Clone for ActorRefStrong<M>[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]

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.

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,