[−][src]Struct bastion::prelude::Callbacks
A set of methods that will get called at different states of
a Supervisor
or Children
life.
Example
Bastion::children(|children| { let callbacks = Callbacks::new() .with_before_start(|| println!("Children group started.")) .with_after_stop(|| println!("Children group stopped.")); children .with_callbacks(callbacks) .with_exec(|ctx| { // -- Children group started. async move { // ... } // -- Children group stopped. }) }).expect("Couldn't create the children group.");
Implementations
impl Callbacks
[src]
pub fn new() -> Self
[src]
Creates a new instance of Callbacks
for
Supervisor::with_callbacks
or Children::with_callbacks
.
Example
Bastion::children(|children| { let callbacks = Callbacks::new() .with_before_start(|| println!("Children group started.")) .with_after_stop(|| println!("Children group stopped.")); children .with_callbacks(callbacks) .with_exec(|ctx| { // -- Children group started. async move { // ... } // -- Children group stopped. }) }).expect("Couldn't create the children group.");
pub fn with_before_start<C>(self, before_start: C) -> Self where
C: Fn() + Send + Sync + 'static,
[src]
C: Fn() + Send + Sync + 'static,
Sets the method that will get called before the Supervisor
or Children
is launched if:
- it was never called before
- or the supervisor of the supervised element using this callback (or the system) decided to restart it and it was already stopped or killed
- or the supervisor of the supervised element using this callback
(or the system) decided to restart it and it wasn't already
stopped or killed but did not have a callback defined using
with_after_restart
Example
supervisor.children(|children| { let callbacks = Callbacks::new() .with_before_start(|| println!("Children group started.")) .with_before_restart(|| println!("Children group restarting.")) .with_after_restart(|| println!("Children group restarted.")) .with_after_stop(|| println!("Children group stopped.")); children .with_exec(|ctx| { // -- Children group started. async move { // ... // This will stop the children group... Ok(()) // Note that because the children group stopped by itself, // if its supervisor restarts it, its `before_start` callback // will get called and not `after_restart`. } // -- Children group stopped. }) .with_callbacks(callbacks) })
pub fn with_before_restart<C>(self, before_restart: C) -> Self where
C: Fn() + Send + Sync + 'static,
[src]
C: Fn() + Send + Sync + 'static,
Sets the method that will get called before the Supervisor
or Children
is reset if:
- the supervisor of the supervised element using this callback (or the system) decided to restart it and it wasn't already stopped or killed
Note that if this callback isn't defined but one was defined using
with_after_stop
, it will get called instead.
Example
supervisor.children(|children| { let callbacks = Callbacks::new() .with_before_start(|| println!("Children group started.")) .with_before_restart(|| println!("Children group restarting.")) .with_after_restart(|| println!("Children group restarted.")) .with_after_stop(|| println!("Children group stopped.")); children .with_exec(|ctx| { // Once -- Children group started. // and then -- Children group restarted. async move { // ... // This will make the children group fault and get // restarted by its supervisor... Err(()) } // -- Children group restarting. // Note that if a `before_restart` wasn't specified for // this children group, `after_stop` would get called // instead. }) .with_callbacks(callbacks) })
pub fn with_after_restart<C>(self, after_restart: C) -> Self where
C: Fn() + Send + Sync + 'static,
[src]
C: Fn() + Send + Sync + 'static,
Sets the method that will get called before the Supervisor
or Children
is launched if:
- the supervisor of the supervised element using this callback (or the system) decided to restart it and it wasn't already stopped or killed
Note that if this callback isn't defined but one was defined using
with_before_start
, it will get called instead.
Example
supervisor.children(|children| { let callbacks = Callbacks::new() .with_before_start(|| println!("Children group started.")) .with_before_restart(|| println!("Children group restarting.")) .with_after_restart(|| println!("Children group restarted.")) .with_after_stop(|| println!("Children group stopped.")); children .with_exec(|ctx| { // Once -- Children group started. // and then -- Children group restarted. // Note that if a `after_restart` callback wasn't specified // for this children group, `before_restart` would get called // instead. async move { // ... // This will make the children group fault and get // restarted by its supervisor... Err(()) } // -- Children group restarting. }) .with_callbacks(callbacks) })
pub fn with_after_stop<C>(self, after_stop: C) -> Self where
C: Fn() + Send + Sync + 'static,
[src]
C: Fn() + Send + Sync + 'static,
Sets the method that will get called after the Supervisor
or Children
is stopped or killed if:
- the supervisor of the supervised element using this callback (or the system) decided to stop (not restart nor kill) it and it wasn't already stopped or killed
- or the supervisor or children group using this callback stopped or killed itself or was stopped or killed by a reference to it
- or the supervisor of the supervised element using this callback
(or the system) decided to restart it and it wasn't already
stopped or killed but did not have a callback defined using
with_before_restart
Example
supervisor.children(|children| { let callbacks = Callbacks::new() .with_before_start(|| println!("Children group started.")) .with_before_restart(|| println!("Children group restarting.")) .with_after_restart(|| println!("Children group restarted.")) .with_after_stop(|| println!("Children group stopped.")); children .with_exec(|ctx| { // -- Children group started. async move { // ... // This will stop the children group... Ok(()) } // -- Children group stopped. // Note that because the children group stopped by itself, // it its supervisor restarts it, its `before_restart` callback // will not get called. }) .with_callbacks(callbacks) })
pub fn has_before_start(&self) -> bool
[src]
Returns whether a callback was defined using with_before_start
.
Example
let callbacks = Callbacks::new() .with_before_start(|| println!("Children group started.")); assert!(callbacks.has_before_start());
pub fn has_before_restart(&self) -> bool
[src]
Returns whether a callback was defined using with_before_restart
.
Example
let callbacks = Callbacks::new() .with_before_restart(|| println!("Children group restarting.")); assert!(callbacks.has_before_restart());
pub fn has_after_restart(&self) -> bool
[src]
Returns whether a callback was defined using with_after_restart
.
Example
let callbacks = Callbacks::new() .with_after_restart(|| println!("Children group restarted.")); assert!(callbacks.has_after_restart());
pub fn has_after_stop(&self) -> bool
[src]
Returns whether a callback was defined using with_after_stop
.
Example
let callbacks = Callbacks::new() .with_after_stop(|| println!("Children group stopped.")); assert!(callbacks.has_after_stop());
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Callbacks
impl Send for Callbacks
impl Sync for Callbacks
impl Unpin for Callbacks
impl !UnwindSafe for Callbacks
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> AsAny for T where
T: Any,
[src]
T: Any,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Message for T where
T: Any + Send + Sync + Debug,
[src]
T: Any + Send + Sync + Debug,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> State for T where
T: Send + Sync + 'static,
[src]
T: Send + Sync + 'static,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,