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::drainruns 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 ofBusholds, refusals and fail-closed points included; a local listener of another thread is queued for that thread’sBus::run_pendingas usual.- Each ask’s outcome is reported by the drain (
PendingRun, withPendingRun::askset): 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
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>
fn drain(&self) -> Vec<PendingRun>
Runs the asks queued for the calling thread, in ask order; what each did. Empty when nothing waits.