pub trait AsyncAutonomousOperator: Sized {
type In;
type Out: 'static;
type Error;
// Required method
fn run(
self,
ctx: Context,
upstreams: Upstreams<Self::In>,
downstream: Downstream<Self::Out>,
) -> impl Future<Output = Result<Fin, Self::Error>>;
}runtime only.Expand description
AutonomousOperator’s ASYNCHRONOUS face — the same owned loop, for a body that has an
.await to spend.
Everything AutonomousOperator states holds here verbatim: the same three seats with the same
types, self taken BY VALUE and its whole lifecycle table with it, the same Fin endings
reused from the origin layer, the same whole-node Err draining before it is answered, the same
unchanged ack vocabulary, the same absence of a Send bound. THE ONLY DIFFERENCE IS THAT THE
ANSWER IS A FUTURE — and the future is PINNED on the node’s own thread rather than spawned, which
is what keeps a !Send body an ordinary citizen here.
The prologue and the epilogue are the same two phases with awaited spellings: an awaited body’s
crew may be tasks rather than threads, and what it closes and awaits are its own — but the
ORDER is the one the blocking face’s table states, and Drop is the same idempotent backstop
under it.
§Why a PAIR and not a defaulted second verb
The dual-mode law, stated in full at AsyncOperator: an author implements EXACTLY ONE face,
and the bound is what says which. A single trait carrying both verbs would make every node answer
a question it has no body for, and a blanket bridge would blind the bound that selects.
use ingraph::{Context, AsyncAutonomousOperator, Downstream, Fin, ShutdownSignal, Upstreams};
struct Waiting {
/// Moved into the loop by the prologue — `self` is this call's, so nothing is borrowed.
budget: usize,
}
impl AsyncAutonomousOperator for Waiting {
type In = u64;
type Out = u64;
type Error = core::convert::Infallible;
async fn run(
self,
ctx: Context,
upstreams: Upstreams<u64>,
_downstream: Downstream<u64>,
) -> Result<Fin, Self::Error> {
let mut left = self.budget;
let Some(edge) = upstreams.edge(0) else {
return Ok(Fin::Spent);
};
while left > 0 {
if ctx.shutdown().is_shutdown() {
return Ok(Fin::Stopped);
}
// The awaited door: the same wait, parked on a runtime instead of a thread.
if edge.park_async().await.is_none() {
return Ok(Fin::Spent);
}
left -= 1;
}
Ok(Fin::Spent)
}
}Required Associated Types§
Sourcetype Out: 'static
type Out: 'static
The message it publishes, 'static for AutonomousOperator::Out’s reason.
Sourcetype Error
type Error
What a life that DIED refuses with. Bound-free here, for Operator::Error’s reason.
Required Methods§
Sourcefn run(
self,
ctx: Context,
upstreams: Upstreams<Self::In>,
downstream: Downstream<Self::Out>,
) -> impl Future<Output = Result<Fin, Self::Error>>
fn run( self, ctx: Context, upstreams: Upstreams<Self::In>, downstream: Downstream<Self::Out>, ) -> impl Future<Output = Result<Fin, Self::Error>>
AutonomousOperator::run, answering a future the engine drives — pinned on the thread this
node owns.
§Errors
AutonomousOperator::run’s, unchanged.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".