Function stateright::actor::spawn

source ·
pub fn spawn<A, E: Debug + 'static>(
    serialize: fn(_: &A::Msg) -> Result<Vec<u8>, E>,
    deserialize: fn(_: &[u8]) -> Result<A::Msg, E>,
    actors: Vec<(impl Into<Id>, A)>
) -> Result<(), Box<dyn Any + Send + 'static>>where
    A: 'static + Send + Actor,
    A::Msg: Debug,
    A::State: Debug,
Expand description

Runs an actor, sending messages over UDP. Blocks the current thread.

Example

use stateright::actor::{Id, spawn};
use std::net::{Ipv4Addr, SocketAddrV4};
let id1 = Id::from(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 3001));
let id2 = Id::from(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 3002));
spawn(
    serde_json::to_vec,
    |bytes| serde_json::from_slice(bytes),
    vec![
        (id1, actor1),
        (id2, actor2),
    ]);