Trait apis::process::Process

source ·
pub trait Process<CTX, RES>
where CTX: Context, RES: Presult<CTX, Self>, Self: TryFrom<CTX::GPROC> + Into<CTX::GPROC>,
{
Show 29 methods // Required methods fn new(inner: Inner<CTX>) -> Self; fn inner_ref(&self) -> &Inner<CTX>; fn inner_mut(&mut self) -> &mut Inner<CTX>; fn result_ref(&self) -> &RES; fn result_mut(&mut self) -> &mut RES; fn global_result(&mut self) -> CTX::GPRES; fn extract_result( session_results: &mut VecMap<CTX::GPRES> ) -> Result<RES, String>; fn handle_message(&mut self, message: CTX::GMSG) -> ControlFlow; fn update(&mut self) -> ControlFlow; // Provided methods fn initialize(&mut self) { ... } fn terminate(&mut self) { ... } fn id(&self) -> &CTX::PID where CTX: 'static { ... } fn kind(&self) -> &Kind where CTX: 'static { ... } fn state_id(&self) -> StateId { ... } fn def(&self) -> &Def<CTX> { ... } fn sourcepoints(&self) -> &VecMap<Box<dyn Sourcepoint<CTX>>> { ... } fn sourcepoints_mut(&mut self) -> &mut VecMap<Box<dyn Sourcepoint<CTX>>> { ... } fn endpoints(&self) -> Ref<'_, Option<VecMap<Box<dyn Endpoint<CTX>>>>> { ... } fn endpoints_mut( &mut self ) -> RefMut<'_, Option<VecMap<Box<dyn Endpoint<CTX>>>>> { ... } fn take_endpoints(&self) -> VecMap<Box<dyn Endpoint<CTX>>> { ... } fn put_endpoints(&self, endpoints: VecMap<Box<dyn Endpoint<CTX>>>) { ... } fn send<M: Message<CTX>>( &self, channel_id: CTX::CID, message: M ) -> Result<(), SendError<CTX::GMSG>> where CTX: 'static { ... } fn send_to<M: Message<CTX>>( &self, channel_id: CTX::CID, recipient: CTX::PID, message: M ) -> Result<(), SendError<CTX::GMSG>> where CTX: 'static { ... } fn run(&mut self) where Self: Sized + 'static, CTX: 'static { ... } fn run_continue(self) -> Option<()> where Self: Sized + 'static, CTX: 'static { ... } fn run_asynchronous(&mut self) where Self: Sized, CTX: 'static { ... } fn run_isochronous(&mut self) where Self: Sized, CTX: 'static { ... } fn run_mesochronous(&mut self) where Self: Sized, CTX: 'static { ... } fn run_anisochronous(&mut self) where Self: Sized, CTX: 'static { ... }
}
Expand description

Main process trait.

Process run loop will end after either all endpoint channels have returned ControlFlow::Break from handle_message() or else if update() returns ControlFlow::Break. Note that after the last endpoint channel has closed a final update() will still be processed. When update() returns ControlFlow::Break, no further handle_message() calls will be made.

Required Methods§

source

fn new(inner: Inner<CTX>) -> Self

source

fn inner_ref(&self) -> &Inner<CTX>

source

fn inner_mut(&mut self) -> &mut Inner<CTX>

source

fn result_ref(&self) -> &RES

source

fn result_mut(&mut self) -> &mut RES

source

fn global_result(&mut self) -> CTX::GPRES

source

fn extract_result( session_results: &mut VecMap<CTX::GPRES> ) -> Result<RES, String>

source

fn handle_message(&mut self, message: CTX::GMSG) -> ControlFlow

source

fn update(&mut self) -> ControlFlow

Provided Methods§

source

fn initialize(&mut self)

Does nothing by default, may be overridden.

source

fn terminate(&mut self)

Does nothing by default, may be overridden.

source

fn id(&self) -> &CTX::PID
where CTX: 'static,

source

fn kind(&self) -> &Kind
where CTX: 'static,

source

fn state_id(&self) -> StateId

source

fn def(&self) -> &Def<CTX>

source

fn sourcepoints(&self) -> &VecMap<Box<dyn Sourcepoint<CTX>>>

source

fn sourcepoints_mut(&mut self) -> &mut VecMap<Box<dyn Sourcepoint<CTX>>>

source

fn endpoints(&self) -> Ref<'_, Option<VecMap<Box<dyn Endpoint<CTX>>>>>

This method returns a Ref <Option <...>> because during the run loop the endpoints will be unavailable as they are being iterated over. Endpoints are automatically waited on or polled in the appropriate run_* function. Endpoints will be present for the calls to terminate or initialize, either before or after the run loop, respectively.

source

fn endpoints_mut( &mut self ) -> RefMut<'_, Option<VecMap<Box<dyn Endpoint<CTX>>>>>

This method returns a Ref <Option <...>> because during the run loop the endpoints will be unavailable as they are being iterated over. Endpoints are automatically waited on or polled in the appropriate run_* function. Endpoints will be present for the calls to terminate or initialize, either before or after the run loop, respectively.

source

fn take_endpoints(&self) -> VecMap<Box<dyn Endpoint<CTX>>>

This method is used within the process run_* methods to get the endpoints without borrowing the process. Endpoints will then be replaced with None and unavailable within the run loop.

Errors

Taking twice is a fatal error.

source

fn put_endpoints(&self, endpoints: VecMap<Box<dyn Endpoint<CTX>>>)

Errors

Error if current endpoints are not None.

source

fn send<M: Message<CTX>>( &self, channel_id: CTX::CID, message: M ) -> Result<(), SendError<CTX::GMSG>>
where CTX: 'static,

source

fn send_to<M: Message<CTX>>( &self, channel_id: CTX::CID, recipient: CTX::PID, message: M ) -> Result<(), SendError<CTX::GMSG>>
where CTX: 'static,

source

fn run(&mut self)
where Self: Sized + 'static, CTX: 'static,

Run a process to completion and send the result on the result channel.

source

fn run_continue(self) -> Option<()>
where Self: Sized + 'static, CTX: 'static,

Run a process to completion, send the result to the session, and proceed with the continuation received from the session.

source

fn run_asynchronous(&mut self)
where Self: Sized, CTX: 'static,

Asynchronous run loop waits for messages on the single endpoint held by this process and calls the process update method for every $n >= 1$ messages as specified by the process kind.

source

fn run_isochronous(&mut self)
where Self: Sized, CTX: 'static,

This function implements a fixed-timestep update loop.

Time is checked immediately after update and the thread is put to sleep for the time remaining until the next update, plus 1 ms since the thread usually wakes up slightly before the set time. In practice this means that the update time lags behind the target time by about 1ms or so, but the time between updates is consistent. If the thread does somehow wake up too early, then no update will be done and the thread will sleep or else loop immediately depending on the result of a second time query.

After an update, if the next (absolute) tick time has already passed, then the thread will not sleep and instead will loop immediately. Note that the tick time is measured on an absolute clock, allowing the thread to “catch up” in case of a long update by processing the “backlog” of ticks as fast as possible.

source

fn run_mesochronous(&mut self)
where Self: Sized, CTX: 'static,

This function implements a rate-limited update loop.

Time is checked immediately after update and the thread is put to sleep for the time remaining until the next update, plus 1 ms since the thread usually wakes up slightly before the set time. In practice this means that the update time lags behind the target time by about 1ms or so, but the time between updates is consistent. If the thread does somehow wake up too early, then no update will be done and the thread will sleep, or else loop immediately depending on the result of a second time query.

After a tick, if the next tick time has already passed, then the thread will not sleep and instead will loop immediately.

source

fn run_anisochronous(&mut self)
where Self: Sized, CTX: 'static,

An un-timed run loop that polls for messages.

Object Safety§

This trait is not object safe.

Implementors§