pub struct SyncContext<M, RT> { /* private fields */ }
Expand description

The context in which a synchronous actor is executed.

This context can be used for a number of things including receiving messages.

Implementations

Attempt to receive the next message.

This will attempt to receive the next message if one is available. If the actor wants to wait until a message is received receive_next can be used, which blocks until a message is ready.

Examples

A synchronous actor that receives a name to greet, or greets the entire world.

use heph::actor::SyncContext;

fn greeter_actor<RT>(mut ctx: SyncContext<String, RT>) {
    if let Ok(name) = ctx.try_receive_next() {
        println!("Hello {}", name);
    } else {
        println!("Hello world");
    }
}

Receive the next message.

Returns the next message available. If no messages are currently available it will block until a message becomes available or until all actor references (that reference this actor) are dropped.

Examples

An actor that waits for a message and prints it.

use heph::actor::SyncContext;

fn print_actor<RT>(mut ctx: SyncContext<String, RT>) {
    if let Ok(msg) = ctx.receive_next() {
        println!("Got a message: {}", msg);
    } else {
        eprintln!("No message received");
    }
}

Block on a Future waiting for it’s completion.

Limitations

Any Future returned by a type that is bound to an actor (see Bound trait of the heph-rt crate) cannot be used by this function. Those types use specialised wake-up mechanisms bypassing the Future’s task system.

Get mutable access to the runtime this actor is running in.

Get access to the runtime this actor is running in.

Trait Implementations

Formats the value using the given formatter. Read more

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.