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

A handle to a task running a crate::traits::Manager.

Represents a shareable/clonable remote to a task running a crate::traits::Manager. Used to send crate::traits::Signal to that task. Initially constructed by the crate::handle::Handle returned on the crate::utils::spawn of the task.

Traits

Represents the handling of crate::traits::Signal in a task. consumed by the crate::utils::spawn function.

Autotrait that constraints the signals that can be sent to a crate::traits::Manager. not ment to be implemented manually

Functions

Spawns a task using the provided crate::Manager and returns a crate::Handle to that task. crate::Signal can be sent through a crate::Remote that can be provided by the crate::Handle.

Attribute Macros