[−][src]Struct bastion::context::BastionContext
Context definition for any lightweight process.
You can use context to:
- spawn children
- communicate with other spawned processes
- communicate with parent
It is used internally for:
- communication with the system
- tracking the supervision
Fields
parent: Option<Box<Supervisor>>
Reference to the parent, it is None for root supervisor.
descendants: Vec<BastionChildren>
Container holding children.
bcast_tx: Option<Sender<Box<dyn Message>>>
Send endpoint for system broadcast.
bcast_rx: Option<Receiver<Box<dyn Message>>>
Receive endpoint for system broadcast.
Methods
impl BastionContext
[src]
pub fn hook(self)
[src]
One-time use hook for spawned processes. You need to have this function for processes which you want to end gracefully by the system after successful completion.
Examples
use bastion::prelude::*; fn main() { Bastion::platform(); Bastion::spawn(|context: BastionContext, _msg: Box<dyn Message>| { println!("root supervisor - spawn_at_root - 1"); // Rebind to the system context.hook(); }, String::from("A Message")); // Comment out to start the system, so runtime can initialize. // Bastion::start() }
pub fn blocking_hook(self)
[src]
Forever running hook for spawned processes. You need to have this function for processes which you want to reutilize the process later and handover the control back again to the system after successful completion.
This function is a must to use for receiving signals from supervision and applying supervision strategies.
Examples
use bastion::prelude::*; fn main() { Bastion::platform(); Bastion::spawn(|context: BastionContext, _msg: Box<dyn Message>| { println!("root supervisor - spawn_at_root - 1"); // Rebind to the system context.blocking_hook(); }, String::from("A Message")); // Comment out to start the system, so runtime can initialize. // Bastion::start() }
pub fn spawn<F, M>(self, thunk: F, msg: M, scale: i32) -> Self where
F: BastionClosure,
M: Message,
[src]
F: BastionClosure,
M: Message,
Context level spawn function for child generation from the parent context. This context carries global broadcast for the system. Every context directly tied to the parent process. If you listen broadcast tx/rx pair in the parent process, you can communicate with the children with specific message type.
Bastion doesn't enforce you to use specific Message type or force you to implement traits. Dynamic dispatch is made over heap fat ptrs and that means all message objects can be passed around with heap constructs.
Arguments
thunk
- User code which will be executed inside the process.msg
- Initial message which will be passed to the thunk.scale
- How many children will be spawn with giventhunk
andmsg
as process body.
Examples
use bastion::prelude::*; fn main() { Bastion::platform(); Bastion::spawn(|context: BastionContext, _msg: Box<dyn Message>| { println!("root supervisor - spawn_at_root - 1"); // Let's spawn a child from here context.clone().spawn( |sub_p: BastionContext, sub_msg: Box<dyn Message>| { receive! { sub_msg, i32 => |msg| { println!("An integer message: {}", msg)}, _ => println!("Message not known") } /// Use blocking hook to commence restart of children /// that has finished their jobs. sub_p.blocking_hook(); }, 9999_i32, // Initial message which is passed down to child. 1, // How many children with this body will be spawned ); // Rebind to the system context.blocking_hook(); }, String::from("A Message")); // Comment out to start the system, so runtime can initialize. // Bastion::start() }
Trait Implementations
impl Default for BastionContext
[src]
fn default() -> BastionContext
[src]
impl Clone for BastionContext
[src]
fn clone(&self) -> BastionContext
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for BastionContext
[src]
Auto Trait Implementations
impl Send for BastionContext
impl Unpin for BastionContext
impl Sync for BastionContext
impl !UnwindSafe for BastionContext
impl !RefUnwindSafe for BastionContext
Blanket Implementations
impl<T> Shell for T where
T: Send + Sync + Clone + Any + 'static,
[src]
T: Send + Sync + Clone + Any + 'static,
impl<T> Message for T where
T: Shell + Debug,
[src]
T: Shell + Debug,
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> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for 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<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Erased for T
impl<T> Clone for T where
T: Clone,
[src]
T: Clone,