aktrs/actor/spawn_options.rs
1use crate::actor::InboxKind;
2
3use std::borrow::Cow;
4use std::time::Duration;
5
6/// The options used to spawn actors into the actor system.
7///
8/// The default spawn options using the following parameters:
9///
10/// * Name: none
11/// * Inbox kind: bounded (32 capacity)
12/// * Throttle: none
13///
14/// # Examples
15///
16/// Spawning a child actor with an unbounded inbox:
17///
18/// ```
19/// use aktrs::actor::{Behavior, Behaviors, InboxKind, SpawnOptions};
20///
21/// let actor = Behaviors::<()>::with_context(|cx| {
22/// let child = Behaviors::<()>::with_context(|cx| {
23/// println!("Hello, world!");
24/// Ok(Behaviors::stopped())
25/// });
26///
27/// cx.spawn(child, SpawnOptions {
28/// inbox_kind: InboxKind::Unbounded,
29/// ..SpawnOptions::default()
30/// });
31///
32/// Ok(Behaviors::stopped())
33/// });
34/// ```
35#[derive(Debug)]
36pub struct SpawnOptions {
37 #[doc(hidden)]
38 /// The name to assign to the spawned actor.
39 pub __private_api_name: Option<Cow<'static, str>>,
40
41 /// The kind of inbox that the actor will use.
42 pub inbox_kind: InboxKind,
43
44 /// The throttle period to apply to the actors inbox.
45 pub throttle: Option<Duration>,
46}
47
48/*
49 impl SpawnOptions
50*/
51
52impl Default for SpawnOptions {
53 fn default() -> Self {
54 Self { __private_api_name: None, inbox_kind: InboxKind::Bounded(32), throttle: None }
55 }
56}