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
Public APIs.
sourcepub fn current_tick(&self) -> TickInstant
pub fn current_tick(&self) -> TickInstant
Gets the current tick (local time) count.
sourcepub fn current_tick_start(&self) -> SystemTime
pub fn current_tick_start(&self) -> SystemTime
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 set_state_tick_hook<T>(
&mut self,
handle: StateHandle<T>,
tick_hook_fn: impl 'static + FnMut(&mut T),
)where
T: Any,
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.
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.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more