pub trait ExecutionObserver:
Send
+ Sync
+ 'static {
// Required method
fn task_finished(&self, event: &TaskEvent<'_>);
}Expand description
Receives one callback per dispatched task.
Object-safe by construction — no generic methods, no associated types — so
this is unrelated to the crate::AsyncFunctionHandler /
DynAsyncFunctionHandler split and needs no Dyn sibling.
Arc<dyn ExecutionObserver> works directly.
§Contract
task_finished is called synchronously, on the executor’s thread,
immediately after the task body returns and before the audit trail is
written. On the sync-built-in path it runs inside the arena scope while the
!Send arena borrow is live.
So an implementation must not block, must not re-enter the engine, and must
not panic — a panic unwinds through the arena scope and out of
process_message. It cannot await, since the method is synchronous. Push to
a channel or bump an atomic and return.
A task whose condition evaluated false is not reported: it was never
dispatched, so there is nothing to time. Tasks that fail are reported, with
status: Some(500) — the event is emitted before the error propagates,
because those are the tasks a host most wants timed.
§Example
use dataflow_rs::{ExecutionObserver, TaskEvent};
use std::sync::atomic::{AtomicU64, Ordering};
#[derive(Default)]
struct TotalMicros(AtomicU64);
impl ExecutionObserver for TotalMicros {
fn task_finished(&self, event: &TaskEvent<'_>) {
// Cheap and non-blocking, as the contract requires.
self.0
.fetch_add(event.duration.as_micros() as u64, Ordering::Relaxed);
}
}Required Methods§
Sourcefn task_finished(&self, event: &TaskEvent<'_>)
fn task_finished(&self, event: &TaskEvent<'_>)
Called once per dispatched task, immediately after its body returns.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".