Struct actix::prelude::Context[][src]

pub struct Context<A> where
    A: Actor<Context = Context<A>>, 
{ /* fields omitted */ }
Expand description

An actor execution context.

Implementations

Create a context without spawning it.

The context can be spawned into an actor using its run method.

struct Actor1 {
    actor2_addr: Addr<Actor2>,
}

struct Actor2 {
    actor1_addr: Addr<Actor1>,
}

let ctx1 = Context::<Actor1>::new();
let ctx2 = Context::<Actor2>::new();

let actor1 = Actor1 { actor2_addr: ctx2.address() };
let actor2 = Actor2 { actor1_addr: ctx1.address() };

ctx1.run(actor1);
ctx2.run(actor2);

Returns a handle to the running future.

This is the handle returned by the AsyncContext::spawn() method.

Sets the mailbox capacity.

The default mailbox capacity is 16 messages. #Examples

struct MyActor;
impl Actor for MyActor {
    type Context = Context<Self>;

    fn started(&mut self, ctx: &mut Self::Context) {
        ctx.set_mailbox_capacity(1);
        System::current().stop();
    }
}

let addr = sys.block_on(async { MyActor.start() });
sys.run();

Returns whether any addresses are still connected.

Trait Implementations

Immediately stop processing incoming messages and switch to a stopping state. This only affects actors that are currently running. Future attempts to queue messages will fail. Read more

Terminate actor execution unconditionally. This sets the actor into the stopped state. This causes future attempts to queue messages to fail. Read more

Retrieve the current Actor execution state.

Spawns a future into the context. Read more

Spawns a future into the context, waiting for it to resolve. Read more

Checks if the context is paused (waiting for future completion or stopping).

Cancels a spawned future. Read more

Returns the address of the context.

Registers a stream with the context. Read more

Registers a stream with the context, ignoring errors. Read more

Sends the message 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. Read more

Sends the message msg to self after a specified period of time. Read more

Executes a closure after a specified period of time. Read more

Spawns a job to execute the given closure periodically, at a specified fixed interval. Read more

Formats the value using the given formatter. Read more

Pack message into suitable envelope

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.