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>
impl<K, T> Pending<K, T>
Sourcepub fn new(state: SnapshotReader<WorldState>, timeout: Option<f32>) -> Self
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.
Sourcepub fn request<F>(
&mut self,
sender: &JobSender,
key: K,
make: F,
) -> Result<(), SendError>
pub fn request<F>( &mut self, sender: &JobSender, key: K, make: F, ) -> Result<(), SendError>
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.
Sourcepub fn advance(
&mut self,
delta_seconds: f32,
settled: &mut Vec<(K, Settled<T>)>,
)
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.
Sourcefn take_outstanding(&mut self, key: &K) -> bool
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>
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>
impl<K, T> Sync for Pending<K, T>
impl<K, T> UnwindSafe for Pending<K, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> Component for Twhere
T: 'static,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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 Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
impl<T> MaybeSync for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<F, T, S> SimdInto<T, S> for Fwhere
T: SimdFrom<F, S>,
S: Simd,
impl<F, T, S> SimdInto<T, S> for Fwhere
T: SimdFrom<F, S>,
S: Simd,
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.