Struct Context

Source
pub struct Context { /* private fields */ }
Expand description

The main state and scheduler of the runtime instance. Provided as the context API to each subgraph/operator as it is run.

Each instance stores eactly one Context inline. 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 loop_iter_count(&self) -> usize

Gets the current loop iteration count.

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 for the next tick.

If is_external is true, the scheduling will trigger the next tick to begin. If it is false then scheduling will be lazy and the next tick will not begin unless there is other reason to.

Source

pub fn reschedule_loop_block(&self)

Schedules the current loop block to be run again (in this tick).

Source

pub fn allow_another_iteration(&self)

Allow another iteration of the loop, if more data comes.

Source

pub fn waker(&self) -> Waker

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

Source

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

Returns a shared reference to the state.

§Safety

StateHandle<T> must be from this instance, created via Self::add_state.

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.

Trait Implementations§

Source§

impl Default for Context

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

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

Source§

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>,

Source§

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
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T