Skip to main content

spawn

Function spawn 

Source
pub fn spawn<A: Actor>(spec: A::Spec) -> Link<A>
Expand description

Spawn a new actor instance with the given specification.

This is a convenience function that delegates to the actor’s associated spawn method, providing a unified interface for actor creation.

§Arguments

  • spec - The specification required to initialize the actor

§Returns

A Link<A> that can be used to send messages to the spawned actor.

§Examples

use actor12::{spawn, Actor, Init, Exec, MpscChannel, Multi};

struct MyActor;

impl Actor for MyActor {
    type Message = Multi<Self>;
    type Spec = ();
    type Channel = MpscChannel<Self::Message>;
    type Cancel = ();
    type State = ();

    fn state(_spec: &Self::Spec) -> Self::State {
        ()
    }

    fn init(_ctx: Init<'_, Self>) -> impl std::future::Future<Output = Result<Self, Self::Cancel>> + Send + 'static {
        std::future::ready(Ok(MyActor))
    }
}

// Spawn the actor
let link = spawn::<MyActor>(());