pub struct SpawnBuilder<'a, Parent, Child, W = NoWatch>{ /* private fields */ }Expand description
Builder for configuring and spawning a child Actor. Created via Ctx::actor.
Implementations§
Source§impl<'a, Parent, Child, W> SpawnBuilder<'a, Parent, Child, W>
impl<'a, Parent, Child, W> SpawnBuilder<'a, Parent, Child, W>
Sourcepub fn supervision(self, supervision: Supervision) -> Self
pub fn supervision(self, supervision: Supervision) -> Self
Sets the Supervision strategy the parent will use for this child.
Defaults to Supervision::Restart with unlimited restarts and no backoff.
§Example
ctx.actor::<Worker>(props)
.supervision(Supervision::Restart {
max: Limit::Amount(3),
backoff: Backoff::Static(Duration::from_secs(1)),
})
.spawn();Sourcepub fn watch<F>(
self,
f: F,
) -> SpawnBuilder<'a, Parent, Child, WatchFn<F, Parent::Msg>>
pub fn watch<F>( self, f: F, ) -> SpawnBuilder<'a, Parent, Child, WatchFn<F, Parent::Msg>>
Registers a callback that fires when the child terminates due to an error.
This happens when the supervision strategy is Supervision::Stop, or when
Supervision::Restart has exhausted all allowed restarts. The callback maps
the child’s error into a message for the parent.
§Example
ctx.actor::<Worker>(props)
.supervision(Supervision::Restart {
max: Limit::Amount(3),
backoff: Backoff::None,
})
.watch(|err| ParentMsg::WorkerDied(format!("{err:?}")))
.spawn();Sourcepub fn spawn_registered(self) -> Result<Handle<Child::Msg>, RegistryError>
pub fn spawn_registered(self) -> Result<Handle<Child::Msg>, RegistryError>
Spawns the child and registers it in the global registry under its type name.
Other actors can then look it up via Ctx::get_handle_for or Ctx::send.
Returns RegistryError::NameTaken if already registered.
Sourcepub fn spawn_named(
self,
name: impl Into<String>,
) -> Result<Handle<Child::Msg>, RegistryError>
pub fn spawn_named( self, name: impl Into<String>, ) -> Result<Handle<Child::Msg>, RegistryError>
Spawns the child and registers it in the global registry under the given name.
Other actors can then look it up via Ctx::get_handle or Ctx::send_to.
Returns RegistryError::NameTaken if the name is already taken.
§Example
let h = ctx.actor::<Worker>(props).spawn_named("worker-1")?;