Expand description
§telecomande
A small crate providing a primitive for the execution of asynchronous tasks by managers through signals.
§Example:
#[tokio::main]
async fn main() {
#[derive(Debug)]
pub enum Signal {
Greet,
Say(String),
}
pub struct Mgr {
greeting: String,
}
#[telecomande::async_trait]
impl telecomande::Manager for Mgr {
type Signal = Signal;
async fn handle(&mut self, signal: Self::Signal) {
match signal {
Signal::Greet => println!("{}", self.greeting),
Signal::Say(text) => println!("{text}"),
}
}
}
let manager = Mgr {
greeting: "Hello".into(),
};
let handle = telecomande::spawn(manager);
let remote = handle.remote();
tokio::spawn(async move {
remote.send(Signal::Greet).unwrap();
remote.send(Signal::Say("telecomande".into())).unwrap();
})
.await
.unwrap();
// out:
// Hello
// telecomande
}
Structs§
- Handle
- A handle to a task running a
crate::Processor
. - Remote
- Represents a shareable/clonable remote to a task running a
crate::Processor
. Used to sendcrate::Command
to that task. Initially constructed by thecrate::Handle
returned on thecrate::Executor::spawn
of the task. - Simple
Executor - Simple implementation of
crate::Executor
, process incommingcrate::Command
s one by one.
Traits§
- Command
- Autotrait that constraints the commands that can be sent to a
crate::Processor
. not ment to be implemented manually - Error
- Autotrait that constraints the kind of errors that can be returned by a
crate::Processor
. not ment to be implemented manually - Executor
- Internal data of a task running and handling incomming
crate::Command
for acrate::Processor
. - Processor
- Represents the handling of
crate::Command
in a task. consumed by acrate::Executor
.