Skip to main content

Pending

Struct Pending 

Source
pub struct Pending<K, T> {
    answerer: Sender<(K, T)>,
    answers: Receiver<(K, T)>,
    state: SnapshotReader<WorldState>,
    timeout: Option<f32>,
    outstanding: Vec<(K, Option<f32>)>,
}
Expand description

The requests one world owes a caller, and the answers that have come back.

One Pending serves one world: it is built with the state that world publishes, and every request made through it goes to it. A caller that asks two worlds for two things keeps two.

K is what the caller names a request by, and T what the world answers with.

Fields§

§answerer: Sender<(K, T)>

What a job publishes its answer through. Cloned into every request.

§answers: Receiver<(K, T)>

Where the answers land, in the order they were published.

§state: SnapshotReader<WorldState>

The state of the world that owes the answers.

§timeout: Option<f32>

How many seconds a request may go unanswered; None waits for as long as the world owes it.

§outstanding: Vec<(K, Option<f32>)>

The requests still outstanding, and how many seconds each has left.

Implementations§

Source§

impl<K, T> Pending<K, T>
where K: Eq + Clone + Send + 'static, T: Send + 'static,

Source

pub fn new(state: SnapshotReader<WorldState>, timeout: Option<f32>) -> Self

Requests for the world state reports on, each allowed to go unanswered for timeout seconds. None waits until the world answers or ends.

Source

pub fn request<F>( &mut self, sender: &JobSender, key: K, make: F, ) -> Result<(), SendError>
where F: FnOnce(&mut World) -> T + Send + 'static,

Ask the world behind sender for what make returns, as the request key names.

make runs once, on the world’s own thread, and whatever it returns is the answer key receives. The send is refused when that world’s queue is full or it has stopped, and then no request is outstanding: the caller decides whether to ask again on a later tick.

A request already outstanding under key is sent again without lengthening its wait: the answer already owed is the one that arrives, and the tick the first was asked on is the one the wait is measured from.

Source

pub fn advance( &mut self, delta_seconds: f32, settled: &mut Vec<(K, Settled<T>)>, )

What ended on this tick: the requests the world answered, and the ones given up on, each under the key it was asked with.

Call it once per tick of the asking world, and take every item it writes: an unanswered request is given up on only once, and an answer is handed out only once. A request is expired when the time it was given runs out, or at once when the world that owed it ended — a job that panicked takes its answer with it, and a world that stopped never runs another.

An answer that arrived for a request no longer outstanding is dropped: the request was given up on, and whatever it asked for has already been dealt with. Requests come out oldest first — the answered in the order the world published them, then the expired in the order they were asked — so two runs of the same durations settle the same requests in the same order.

settled is cleared and reused, so a caller that keeps one allocates nothing per tick but what the answers themselves weigh.

Source

fn take_outstanding(&mut self, key: &K) -> bool

Whether a request named key is still owed, taking it out if it is.

Auto Trait Implementations§

§

impl<K, T> !Unpin for Pending<K, T>

§

impl<K, T> !UnsafeUnpin for Pending<K, T>

§

impl<K, T> Forget for Pending<K, T>

§

impl<K, T> Freeze for Pending<K, T>
where Sender<(K, T)>: Freeze, Receiver<(K, T)>: Freeze, Vec<(K, Option<f32>)>: Freeze,

§

impl<K, T> RefUnwindSafe for Pending<K, T>
where Sender<(K, T)>: RefUnwindSafe, Receiver<(K, T)>: RefUnwindSafe, Vec<(K, Option<f32>)>: RefUnwindSafe,

§

impl<K, T> Send for Pending<K, T>
where Sender<(K, T)>: Send, Receiver<(K, T)>: Send, Vec<(K, Option<f32>)>: Send,

§

impl<K, T> Sync for Pending<K, T>
where Sender<(K, T)>: Sync, Receiver<(K, T)>: Sync, Vec<(K, Option<f32>)>: Sync,

§

impl<K, T> UnwindSafe for Pending<K, T>
where Sender<(K, T)>: UnwindSafe, Receiver<(K, T)>: UnwindSafe, Vec<(K, Option<f32>)>: UnwindSafe,

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> DowncastSend for T
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

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
§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> MaybeSync for T
where T: Sync + ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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

§

fn upcast(&self) -> Option<&T>

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,

§

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