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
impl Context
sourcepub fn current_tick(&self) -> usize
pub fn current_tick(&self) -> usize
Gets the current tick (local time) count.
sourcepub fn current_tick_start(&self) -> Instant
pub fn current_tick_start(&self) -> Instant
Gets the timestamp of the beginning of the current tick.
sourcepub fn is_first_run_this_tick(&self) -> bool
pub fn is_first_run_this_tick(&self) -> bool
Gets whether this is the first time this subgraph is being scheduled for this tick
sourcepub fn current_stratum(&self) -> usize
pub fn current_stratum(&self) -> usize
Gets the current stratum nubmer.
sourcepub fn current_subgraph(&self) -> SubgraphId
pub fn current_subgraph(&self) -> SubgraphId
Gets the ID of the current subgraph.
sourcepub fn schedule_subgraph(&self, sg_id: SubgraphId, is_external: bool)
pub fn schedule_subgraph(&self, sg_id: SubgraphId, is_external: bool)
Schedules a subgraph.
sourcepub fn waker(&self) -> Waker
pub fn waker(&self) -> Waker
Returns a Waker
for interacting with async Rust.
Waker events are considered to be extenral.
sourcepub fn state_ref<T>(&self, handle: StateHandle<T>) -> &Twhere
T: Any,
pub fn state_ref<T>(&self, handle: StateHandle<T>) -> &Twhere
T: Any,
Returns a shared reference to the state.
sourcepub fn state_mut<T>(&mut self, handle: StateHandle<T>) -> &mut Twhere
T: Any,
pub fn state_mut<T>(&mut self, handle: StateHandle<T>) -> &mut Twhere
T: Any,
Returns an exclusive reference to the state.
sourcepub fn add_state<T>(&mut self, state: T) -> StateHandle<T>where
T: Any,
pub fn add_state<T>(&mut self, state: T) -> StateHandle<T>where
T: Any,
Adds state to the context and returns the handle.
sourcepub fn remove_state<T>(&mut self, handle: StateHandle<T>) -> Box<T>where
T: Any,
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.
sourcepub fn request_task<Fut>(&mut self, future: Fut)
pub fn request_task<Fut>(&mut self, future: Fut)
Prepares an async task to be launched by Self::spawn_tasks
.
sourcepub fn spawn_tasks(&mut self)
pub fn spawn_tasks(&mut self)
Launches all tasks requested with Self::request_task
on the internal Tokio executor.
sourcepub fn abort_tasks(&mut self)
pub fn abort_tasks(&mut self)
Aborts all tasks spawned with Self::spawn_tasks
.
sourcepub async fn join_tasks(&mut self)
pub async fn join_tasks(&mut self)
Waits for all tasks spawned with Self::spawn_tasks
to complete.
Will probably just hang.