/// Creates a new `Supervisor`, passes it through the specified
/// `init` closure and then starts supervising it.
///
/// If you need to chain calls to this `Supervisor`'s methods and
/// don't need to get a [`SupervisorRef`] referencing the newly
/// created supervisor, use the [`supervisor`] method instead.
///
/// # Arguments
///
/// * `init` - The closure taking the new `Supervisor` as an
///     argument and returning it once configured.
///
/// # Example
///
/// ```rust
/// # use bastion::prelude::*;
/// #
/// # #[cfg(feature = "tokio-runtime")]
/// # #[tokio::main]
/// # async fn main() {
/// #    run();    
/// # }
/// #
/// # #[cfg(not(feature = "tokio-runtime"))]
/// # fn main() {
/// #    run();    
/// # }
/// #
/// # fn run() {
/// # Bastion::init();
/// #
/// # Bastion::supervisor(|mut parent| {
/// let sp_ref: SupervisorRef = parent.supervisor_ref(|sp| {
///     // Configure the supervisor...
///     sp.with_strategy(SupervisionStrategy::OneForOne)
///     // ...and return it.
/// });
///     # parent
/// # }).unwrap();
/// #
/// # Bastion::start();
/// # Bastion::stop();
/// # Bastion::block_until_stopped();
/// # }
/// ```
///
/// [`supervisor`]: Self::supervisor
Creates a new `Supervisor`, passes it through the specified
`init` closure and then starts supervising it.


Creates a new ` Supervisor ` passes it through the specified ` init ` closure and then starts supervising it .
pub fn supervisor_ref<S>(&mut self, init: S) -> SupervisorRef
    where
        S: FnOnce(Supervisor) -> Supervisor,
    {
        debug!("Supervisor({}): Creating supervisor.", self.id());
        let parent = Parent::supervisor(self.as_ref());
        let bcast = Broadcast::new(parent, BastionPathElement::Supervisor(BastionId::new()));
        debug!(
            "Supervisor({}): Initializing Supervisor({}).",
            self.id(),
            bcast.id()
        );
        let supervisor = Supervisor::new(bcast);
        let supervisor = init(supervisor);
        debug!("Supervisor({}): Initialized.", supervisor.id());
        let supervisor_ref = supervisor.as_ref();
        debug!(
            "Supervisor({}): Deploying Supervisor({}).",
            self.id(),
            supervisor.id()
        );
        let msg = BastionMessage::deploy_supervisor(supervisor);
        let env = Envelope::new(msg, self.bcast.path().clone(), self.bcast.sender().clone());
        self.bcast.send_self(env);
        supervisor_ref
    }
pub fn supervisor_ref < S > ( & mut self , init : S ) -> SupervisorRef where S : FnOnce ( Supervisor ) -> Supervisor , { debug ! ( " " self id ( ) ) ; let parent = Parent :: supervisor ( self . as_ref ( ) ) ; let bcast = Broadcast :: new ( parent , BastionPathElement :: Supervisor ( BastionId :: new ( ) ) ) ; debug ! ( " " self id ( ) bcast id ( ) ) ; let supervisor = Supervisor :: new ( bcast ) ; let supervisor = init ( supervisor ) ; debug ! ( " " supervisor id ( ) ) ; let supervisor_ref = supervisor . as_ref ( ) ; debug ! ( " " self id ( ) supervisor id ( ) ) ; let msg = BastionMessage :: deploy_supervisor ( supervisor ) ; let env = Envelope :: new ( msg , self . bcast . path ( ) . clone ( ) , self . bcast . sender ( ) . clone ( ) ) ; self . bcast . send_self ( env ) ; supervisor_ref }
Creates a new `Supervisor`, passes it through the specified
`init` closure and then starts supervising it.
Creates a new ` Supervisor ` passes it through the specified ` init ` closure and then starts supervising it .
&mut self
init
S
example
None
use bastion::prelude::*;
None
#[cfg(feature = "tokio-runtime")]
None
#[tokio::main]
None
async fn main() {
None
run();    
None
}
None
#[cfg(not(feature = "tokio-runtime"))]
None
fn main() {
None
run();    
None
}
None
fn run() {
None
bastion::init();
None
bastion::supervisor(|mut parent| {
let sp_ref: SupervisorRef = parent.supervisor_ref(|sp| {
Configure the supervisor
sp.with_strategy(SupervisionStrategy::OneForOne)
and return it.
});
parent
let sp_ref : SupervisorRef = parent . supervisor_ref ( |sp| { Configure the supervisor sp . with_strategy ( SupervisionStrategy :: OneForOne ) and return it . } ) ; parent
}).unwrap();
None
bastion::start();
None
bastion::stop();
None
bastion::block_until_stopped();
None
}
None