Skip to main content

reifydb_runtime/actor/
traits.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4use crate::actor::{context::Context, system::ActorConfig};
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum Directive {
8	Continue,
9
10	Yield,
11
12	Park,
13
14	Stop,
15}
16
17pub trait Actor: Send + Sync + 'static {
18	type State: Send + 'static;
19
20	type Message: Send + 'static;
21
22	fn init(&self, ctx: &Context<Self::Message>) -> Self::State;
23
24	fn handle(&self, state: &mut Self::State, msg: Self::Message, ctx: &Context<Self::Message>) -> Directive;
25
26	#[allow(unused_variables)]
27	fn idle(&self, ctx: &Context<Self::Message>) -> Directive {
28		Directive::Park
29	}
30
31	fn post_stop(&self) {}
32
33	fn config(&self) -> ActorConfig {
34		ActorConfig::default()
35	}
36}