amico_core/traits/
event_source.rs

1use tokio::task::JoinHandle;
2use tokio_with_wasm::alias as tokio;
3
4use crate::types::AgentEvent;
5
6/// An event source listens for events, and calls the `on_event`
7/// callback to react to events.
8pub trait EventSource {
9    /// The method to run the `EventSource`.
10    ///
11    /// The `run` method will be called by `Agent` in a new thread.
12    fn spawn<F, Fut>(&self, on_event: F) -> JoinHandle<anyhow::Result<()>>
13    where
14        F: Fn(AgentEvent) -> Fut + Send + Sync + 'static,
15        Fut: Future<Output = ()> + Send + 'static;
16}