Struct hydroflow::scheduled::context::Context

source ·
pub struct Context { /* private fields */ }
Expand description

The main state of the Hydroflow instance, which is provided as a reference to each operator as it is run.

As an optimization, each Hydroflow instances stores eactly one Context inline, which allows us to avoid any construction/deconstruction costs. Before the Context is provided to a running operator, the subgraph_id field must be updated.

Implementations§

source§

impl Context

Public APIs.

source

pub fn current_tick(&self) -> TickInstant

Gets the current tick (local time) count.

source

pub fn current_tick_start(&self) -> SystemTime

Gets the timestamp of the beginning of the current tick.

source

pub fn is_first_run_this_tick(&self) -> bool

Gets whether this is the first time this subgraph is being scheduled for this tick

source

pub fn current_stratum(&self) -> usize

Gets the current stratum nubmer.

source

pub fn current_subgraph(&self) -> SubgraphId

Gets the ID of the current subgraph.

source

pub fn schedule_subgraph(&self, sg_id: SubgraphId, is_external: bool)

Schedules a subgraph.

source

pub fn waker(&self) -> Waker

Returns a Waker for interacting with async Rust. Waker events are considered to be extenral.

source

pub fn state_ref<T>(&self, handle: StateHandle<T>) -> &T
where T: Any,

Returns a shared reference to the state.

source

pub fn state_mut<T>(&mut self, handle: StateHandle<T>) -> &mut T
where T: Any,

Returns an exclusive reference to the state.

source

pub fn add_state<T>(&mut self, state: T) -> StateHandle<T>
where T: Any,

Adds state to the context and returns the handle.

source

pub fn set_state_tick_hook<T>( &mut self, handle: StateHandle<T>, tick_hook_fn: impl 'static + FnMut(&mut T), )
where T: Any,

Sets a hook to modify the state at the end of each tick, using the supplied closure.

source

pub fn remove_state<T>(&mut self, handle: StateHandle<T>) -> Box<T>
where T: Any,

Removes state from the context returns it as an owned heap value.

source

pub fn request_task<Fut>(&mut self, future: Fut)
where Fut: Future<Output = ()> + 'static,

Prepares an async task to be launched by Self::spawn_tasks.

source

pub fn spawn_tasks(&mut self)

Launches all tasks requested with Self::request_task on the internal Tokio executor.

source

pub fn abort_tasks(&mut self)

Aborts all tasks spawned with Self::spawn_tasks.

source

pub async fn join_tasks(&mut self)

Waits for all tasks spawned with Self::spawn_tasks to complete.

Will probably just hang.

Auto Trait Implementations§

§

impl Freeze for Context

§

impl !RefUnwindSafe for Context

§

impl !Send for Context

§

impl !Sync for Context

§

impl Unpin for Context

§

impl !UnwindSafe for Context

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more