Skip to main content

Defer

Trait Defer 

pub trait Defer: Send + Sync {
    // Required methods
    fn ask_any(
        &self,
        point: PointKey,
        input: Arc<dyn Any + Sync + Send>,
        value: Box<dyn Any + Send>,
        clone: fn(&(dyn Any + Send + 'static)) -> Box<dyn Any + Send>,
    ) -> u64;
    fn drain(&self) -> Vec<PendingRun>;
    fn waiting(&self) -> usize;
}
Expand description

A capability of a bus (BusDefer::defer): a request asked now, whose listeners run at the bus’s next drain on the same thread.

It is for code that cannot be re-entered while it runs, such as an interface drawing a panel with its state borrowed: the panel asks, and the listeners run after the drawing, when the host calls Defer::drain.

What an implementation promises:

  • An ask is queued for the calling thread and returns at once with its number, increasing in ask order across the bus. The wakers (Bus::add_pending_waker) are called with the thread’s id.
  • Defer::drain runs the asks queued for the calling thread, in ask order, each as an alter emit of its point with the listeners registered when it runs (one removed since the ask does not run; one added since does). Every rule of Bus holds, refusals and fail-closed points included; a local listener of another thread is queued for that thread’s Bus::run_pending as usual.
  • Each ask’s outcome is reported by the drain (PendingRun, with PendingRun::ask set): the listeners that ran, their failures, a refusal. The asker gets nothing back; a listener placed last (ListenOpts::last) reads the final value.
  • An ask made during a drain (by a listener) waits for the next one.
  • An immediate emit made after an ask, before the drain, runs before it.

Required Methods§

fn ask_any( &self, point: PointKey, input: Arc<dyn Any + Sync + Send>, value: Box<dyn Any + Send>, clone: fn(&(dyn Any + Send + 'static)) -> Box<dyn Any + Send>, ) -> u64

Queues an alter emit of point with input and value for the calling thread’s next Defer::drain; the ask’s number.

fn drain(&self) -> Vec<PendingRun>

Runs the asks queued for the calling thread, in ask order; what each did. Empty when nothing waits.

fn waiting(&self) -> usize

How many asks wait for the calling thread’s drain (zero before a clean exit).

Implementations§

§

impl<'a> dyn Defer + 'a

pub fn ask<P>( &self, input: <P as Point>::Input, value: <P as Point>::Value, ) -> u64
where P: Point, <P as Point>::Value: Clone,

Asks the request P now: its listeners run at the calling thread’s next Defer::drain. The ask’s number.

Implementors§

§

impl Defer for Kernel