Struct barley_runtime::Context
source · pub struct Context<'ctx> { /* private fields */ }Expand description
A context for running actions.
There should only be one of these per workflow
Implementations§
source§impl<'ctx> Context<'ctx>
impl<'ctx> Context<'ctx>
sourcepub fn new(callbacks: ContextCallbacks) -> Self
pub fn new(callbacks: ContextCallbacks) -> Self
Create a new context with the given callbacks.
If you don’t want any callbacks, it’s recommended
to use the Default implementation instead.
sourcepub fn add_action<A: Action + 'ctx>(
&mut self,
action: A
) -> Arc<dyn Action + 'ctx>
pub fn add_action<A: Action + 'ctx>( &mut self, action: A ) -> Arc<dyn Action + 'ctx>
Add an action to the context.
This method adds an action to the context, and returns a reference to the action. The action will be run when the context is run.
You can use the returned reference as a dependency for other actions.
sourcepub async fn run(&mut self) -> Result<()>
pub async fn run(&mut self) -> Result<()>
Run the context.
While processing the actions, it will call the callbacks if they are set.
sourcepub fn set_variable(&mut self, name: &str, value: &str)
pub fn set_variable(&mut self, name: &str, value: &str)
Sets a variable in the context.
This can be used to send information between actions. For example, you could set a return code in one action, and check it in another.
sourcepub fn get_variable(&self, name: &str) -> Option<&str>
pub fn get_variable(&self, name: &str) -> Option<&str>
Gets a variable from the context.
If the variable doesn’t exist, this method
returns None.