sprite-core 0.1.0

Sprite Engine — a fault-tolerant actor runtime for Rust
Documentation
use crate::engine::{Engine, Handle};
use crate::actor::Context;
use std::time::Duration;

/// Fluent builder for spawning actors with configuration.
pub struct ActorBuilder<F>
where
    F: Fn(&mut Context) + Send + Sync + 'static,
{
    name: String,
    setup: F,
    arena_size: usize,
    max_recoveries: u32,
    recovery_window: Duration,
}

impl<F> ActorBuilder<F>
where
    F: Fn(&mut Context) + Send + Sync + 'static,
{
    pub fn new(name: &str, setup: F) -> Self {
        Self {
            name: name.to_string(),
            setup,
            arena_size: 1024 * 64,
            max_recoveries: 10,
            recovery_window: Duration::from_secs(5),
        }
    }

    pub fn arena_size(mut self, bytes: usize) -> Self {
        self.arena_size = bytes;
        self
    }

    pub fn max_recoveries(mut self, n: u32) -> Self {
        self.max_recoveries = n;
        self
    }

    pub fn recovery_window(mut self, d: Duration) -> Self {
        self.recovery_window = d;
        self
    }

    pub fn spawn(self, engine: &Engine) -> Handle {
        engine.spawn_with_config(&self.name, self.setup, self.arena_size, self.max_recoveries, self.recovery_window)
    }
}