pub enum Handled {
Ok,
BlockOn(BlockingFuture),
Shutdown,
}Expand description
State transition indication at the end of a message or event handler.
Variants§
Ok
Continue as normal
BlockOn(BlockingFuture)
Immediately suspend processing of any messages and events
until the BlockingFuture has completed
Shutdown
Shut the component down without handling any further messages.
This is an orderly shutdown result. Use HandlerError::Unrecoverable for terminal faults.
Implementations§
Source§impl Handled
impl Handled
Sourcepub const OK: Result<Handled, HandlerError>
pub const OK: Result<Handled, HandlerError>
A successful no-op handler result.
Sourcepub const SHUTDOWN: Result<Handled, HandlerError>
pub const SHUTDOWN: Result<Handled, HandlerError>
A successful shutdown handler result.
Sourcepub fn block_on<CD, F>(
component: &mut CD,
fun: impl FnOnce(ComponentDefinitionAccess<CD>) -> F,
) -> Result<Handled, HandlerError>where
CD: ComponentDefinition + 'static,
F: Future<Output = Result<Handled, HandlerError>> + Send + 'static,
pub fn block_on<CD, F>(
component: &mut CD,
fun: impl FnOnce(ComponentDefinitionAccess<CD>) -> F,
) -> Result<Handled, HandlerError>where
CD: ComponentDefinition + 'static,
F: Future<Output = Result<Handled, HandlerError>> + Send + 'static,
Constructs a state transition instruction which causes
the component to suspend processing of any messages and events
until the async fun (the returned Future) has completed.
Mutable access to the component’s internal state is provided via the ComponentDefinitionAccess guard object.
Please see the documentation for ComponentDefinitionAccess for details on how the internal state may (and may not) be used.
§Example
#[derive(ComponentDefinition, Actor)]
struct AsyncComponent {
ctx: ComponentContext<Self>,
flag: bool,
}
impl AsyncComponent {
fn new() -> Self {
AsyncComponent {
ctx: ComponentContext::uninitialised(),
flag: false,
}
}
}
impl ComponentLifecycle for AsyncComponent {
fn on_start(&mut self) -> HandlerResult {
// on nightly you can just write: async move |mut async_self| {...}
Handled::block_on(self, move |mut async_self| async move {
async_self.flag = true;
Handled::OK
})
}
}§See Also
In order to continue processing messages and events in parallel to completing the future use spawn_local.
In order to run a large future which does not need access to component’s internal state at all or until the very end, consider using spawn_off.
Sourcepub fn is_ok(&self) -> bool
pub fn is_ok(&self) -> bool
Returns true if this instance is an Handled::Ok variant