Skip to main content

rskit_worker/
handler.rs

1use tokio::sync::mpsc;
2use tokio_util::sync::CancellationToken;
3
4use rskit_errors::AppResult;
5
6use crate::event::Event;
7
8/// Core trait for worker task handlers.
9///
10/// Implementors receive a task `I`, an event sender for streaming intermediate results,
11/// and a cancellation token for cooperative cancellation.
12#[async_trait::async_trait]
13pub trait Handler<I, O>: Send + Sync
14where
15    I: Send + 'static,
16    O: Send + Clone + 'static,
17{
18    /// Execute the task, emitting intermediate events via `emit` and
19    /// honouring cancellation requests via `cancel`.
20    async fn handle(
21        &self,
22        task: I,
23        emit: mpsc::Sender<Event<O>>,
24        cancel: CancellationToken,
25    ) -> AppResult<O>;
26}