pub enum Agent<T = ()> {
Stop(T),
Continue(T),
}
Expand description
See the crate’s main documentation for a description of what an Agent
is.
The Agent
is also an enum that can be used to control the Agent
when using Handle::call
.
Variants§
Implementations§
Source§impl<T> Agent<T>
impl<T> Agent<T>
Sourcepub fn spawn_thread_named<F>(
initial_state: F,
name: String,
) -> Result<Handle<T>>
pub fn spawn_thread_named<F>( initial_state: F, name: String, ) -> Result<Handle<T>>
Spawns an agent that will manage the state returned by the initial_state
function in its own thread.
This function is identical to Agent::spawn_thread
, except that it allows for you to name the thread.
Sourcepub fn spawn_thread<F>(initial_state: F) -> Result<Handle<T>>
pub fn spawn_thread<F>(initial_state: F) -> Result<Handle<T>>
Spawns an agent that will manage the state returned by initial_state
in its own thread.
The thread will be named after the type returned by initial_state
.
Sourcepub fn spawn_task<F>(initial_state: F) -> Handle<T>
pub fn spawn_task<F>(initial_state: F) -> Handle<T>
Spawns an agent that will manage the state returned by initial_state
a task using tokio::task::spawn.
This function must be called from the context of a Tokio runtime.
§Panics
Panics if called from outside of the Tokio runtime.
Sourcepub fn spawn_local_task<F>(initial_state: F) -> Handle<T>where
F: FnOnce() -> T + 'static,
T: 'static,
pub fn spawn_local_task<F>(initial_state: F) -> Handle<T>where
F: FnOnce() -> T + 'static,
T: 'static,
Spawns an agent that will manage the state returned by initial_state
in a local task using tokio::task::spawn_local.
The agent will be run on the same thread that called spawn_local.
This may only be called from the context
of a local task set.
§Panics
Panics if called outside of a local task set.