pub trait EventDomainRun: Debug + Send {
// Required methods
fn domain(&self) -> EventDomainId;
fn enqueue(
&mut self,
dependencies: &[Arc<dyn EventToken>],
launch: &mut dyn FnMut() -> Result<()>,
) -> Result<Arc<dyn EventToken>>;
fn drain(&mut self) -> Result<()>;
}Expand description
Per-execution state owned by one event domain.
§Examples
use tenferro_runtime::{EventDomainId, EventDomainRun};
fn submit(
run: &mut dyn EventDomainRun,
domain: EventDomainId,
) -> tenferro_runtime::Result<()> {
assert_eq!(run.domain(), domain);
let mut launch = || Ok(());
run.enqueue(&[], &mut launch)?;
run.drain()
}Required Methods§
Sourcefn domain(&self) -> EventDomainId
fn domain(&self) -> EventDomainId
Return the exact domain admitted by this run.
§Examples
use tenferro_runtime::{EventDomainId, EventDomainRun};
fn inspect(run: &dyn EventDomainRun, expected: EventDomainId) {
assert_eq!(run.domain(), expected);
}Sourcefn enqueue(
&mut self,
dependencies: &[Arc<dyn EventToken>],
launch: &mut dyn FnMut() -> Result<()>,
) -> Result<Arc<dyn EventToken>>
fn enqueue( &mut self, dependencies: &[Arc<dyn EventToken>], launch: &mut dyn FnMut() -> Result<()>, ) -> Result<Arc<dyn EventToken>>
Enqueue one launch after its dependency tokens.
§Errors
Returns a typed runtime error when a dependency token is incompatible
with this domain, native queue submission fails, or launch returns an
error.
The implementation must not invoke launch when dependency admission
or waiting fails. After dependencies are admitted, it invokes launch
exactly once without holding a driver lock. The closure submits work to
the native queue; it does not wait for that work to complete.
§Examples
use tenferro_runtime::EventDomainRun;
fn submit(run: &mut dyn EventDomainRun) -> tenferro_runtime::Result<()> {
let mut launched = false;
let mut launch = || {
launched = true;
Ok(())
};
run.enqueue(&[], &mut launch)?;
assert!(launched);
Ok(())
}Sourcefn drain(&mut self) -> Result<()>
fn drain(&mut self) -> Result<()>
Wait for all work already enqueued in this run.
§Errors
Returns the first driver-defined typed error, such as
crate::Error::Internal, when a queued completion reports failure or
the native queue cannot be synchronized.
Success and error are both retirement boundaries: before returning, the run must ensure that no previously enqueued work can access tensors, tokens, or native resources retained by the caller. An error reports the completion failure; it must not mean that work is still using those resources. Implementations must not unwind from this method.
Draining observes already-progressing work. It must not require another event domain’s drain call to start that work.
Dropping a run must perform equivalent best-effort retirement when explicit draining is skipped by panic unwinding. Neither explicit draining nor implicit retirement may unwind into the caller.