rill_engine/tracers/
meio_addon.rs

1//! Adds `meio` integraion to `Tracer`.
2
3use super::tracer::Tracer;
4use meio::{Action, ActionHandler, Actor, Context};
5use rill_protocol::flow::core::{ActionEnvelope, Flow};
6
7/// Tracer action for `meio` actor.
8pub struct TracerAction<T: Flow, Tag = ()> {
9    /// Assigned envelope with an `Action`.
10    pub envelope: ActionEnvelope<T>,
11    /// Assigned tag of the action.
12    pub tag: Tag,
13}
14
15impl<T: Flow, Tag: Send + 'static> Action for TracerAction<T, Tag> {}
16
17impl<T: Flow> Tracer<T> {
18    /// Forward `Tracer` events to an `Actor`.
19    pub fn forward<A: Actor, Tag>(&self, tag: Tag, ctx: &mut Context<A>)
20    where
21        A: ActionHandler<TracerAction<T, Tag>>,
22        Tag: Clone + Send + Sync + 'static,
23    {
24        let addr = ctx.address().clone();
25        self.async_callback(move |envelope| {
26            let mut addr = addr.clone();
27            let tag = tag.clone();
28            async move {
29                let msg = TracerAction { envelope, tag };
30                addr.act(msg).await
31            }
32        });
33    }
34}