Skip to main content

ChildSpec

Struct ChildSpec 

Source
pub struct ChildSpec {
    pub name: String,
    pub function: u32,
    pub args: Vec<Value>,
    pub restart: RestartPolicy,
}
Expand description

A child the supervisor should start (and possibly restart).

function is an index into the runtime’s chunk — the same number super::runtime::Runtime::spawn takes. Args are cloned on every restart so a child always comes back with the original call.

Non-empty Self::name is registered as register_name → a SEND|ASK Cap for that incarnation (swept on exit, re-bound on restart).

Fields§

§name: String§function: u32§args: Vec<Value>§restart: RestartPolicy

Implementations§

Source§

impl ChildSpec

Source

pub fn new(name: impl Into<String>, function: u32) -> Self

Examples found in repository?
examples/crash_and_restart.rs (line 49)
15fn main() {
16    let rt = match Runtime::with_config(
17        samples::boom(),
18        RuntimeConfig {
19            workers: 1,
20            quantum: 1_000,
21            mailbox: byteflow::MailboxConfig::DEFAULT,
22            ..Default::default()
23        },
24    ) {
25        Ok(rt) => rt,
26        Err(e) => {
27            eprintln!("runtime: {e}");
28            std::process::exit(1);
29        }
30    };
31    let Some(boom) = rt.function_index("boom") else {
32        eprintln!("missing boom");
33        std::process::exit(1);
34    };
35    let sup = match Supervisor::with_config(
36        rt.spawner(),
37        SupervisorConfig {
38            max_restarts: 2,
39            max_period: Duration::from_secs(5),
40            strategy: byteflow::RestartStrategy::OneForOne,
41        },
42    ) {
43        Ok(s) => s,
44        Err(e) => {
45            eprintln!("supervisor: {e}");
46            std::process::exit(1);
47        }
48    };
49    if let Err(e) = sup.start_child(ChildSpec::new("boom", boom).restart(RestartPolicy::OnFailure))
50    {
51        eprintln!("start_child: {e}");
52        std::process::exit(1);
53    }
54
55    let start = std::time::Instant::now();
56    while !sup.intensity_exceeded() {
57        if start.elapsed() > Duration::from_secs(2) {
58            eprintln!("supervisor did not hit intensity in time");
59            std::process::exit(1);
60        }
61        thread::sleep(Duration::from_millis(5));
62    }
63
64    let metrics = rt.metrics();
65    println!("intensity exceeded after {} failures", metrics.processes_failed);
66    println!("{metrics}");
67    sup.shutdown();
68    rt.shutdown();
69}
Source

pub fn args(self, args: Vec<Value>) -> Self

Source

pub fn restart(self, restart: RestartPolicy) -> Self

Examples found in repository?
examples/crash_and_restart.rs (line 49)
15fn main() {
16    let rt = match Runtime::with_config(
17        samples::boom(),
18        RuntimeConfig {
19            workers: 1,
20            quantum: 1_000,
21            mailbox: byteflow::MailboxConfig::DEFAULT,
22            ..Default::default()
23        },
24    ) {
25        Ok(rt) => rt,
26        Err(e) => {
27            eprintln!("runtime: {e}");
28            std::process::exit(1);
29        }
30    };
31    let Some(boom) = rt.function_index("boom") else {
32        eprintln!("missing boom");
33        std::process::exit(1);
34    };
35    let sup = match Supervisor::with_config(
36        rt.spawner(),
37        SupervisorConfig {
38            max_restarts: 2,
39            max_period: Duration::from_secs(5),
40            strategy: byteflow::RestartStrategy::OneForOne,
41        },
42    ) {
43        Ok(s) => s,
44        Err(e) => {
45            eprintln!("supervisor: {e}");
46            std::process::exit(1);
47        }
48    };
49    if let Err(e) = sup.start_child(ChildSpec::new("boom", boom).restart(RestartPolicy::OnFailure))
50    {
51        eprintln!("start_child: {e}");
52        std::process::exit(1);
53    }
54
55    let start = std::time::Instant::now();
56    while !sup.intensity_exceeded() {
57        if start.elapsed() > Duration::from_secs(2) {
58            eprintln!("supervisor did not hit intensity in time");
59            std::process::exit(1);
60        }
61        thread::sleep(Duration::from_millis(5));
62    }
63
64    let metrics = rt.metrics();
65    println!("intensity exceeded after {} failures", metrics.processes_failed);
66    println!("{metrics}");
67    sup.shutdown();
68    rt.shutdown();
69}

Trait Implementations§

Source§

impl Clone for ChildSpec

Source§

fn clone(&self) -> ChildSpec

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ChildSpec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.