pub struct LocalPollAdapter<'a, S, K, R> {
pool: FuturesUnordered<LocalBoxFuture<'a, (K, R)>>,
cache: HashMap<K, Poll<R>>,
self_parameter: S,
}Expand description
A local (!Send) adapter for caching and executing an async method from a non-async context.
The self_parameter, key, and successful (Ok) results must all be cheap to clone.
Ensures at most one in-flight computation per key. Results are:
- cached on success
- not retained on error
Fields§
§pool: FuturesUnordered<LocalBoxFuture<'a, (K, R)>>§cache: HashMap<K, Poll<R>>§self_parameter: SImplementations§
Source§impl<'a, S, K, V, E> LocalPollAdapter<'a, S, K, Result<V, E>>
impl<'a, S, K, V, E> LocalPollAdapter<'a, S, K, Result<V, E>>
pub fn new(self_parameter: S) -> Self
Sourcepub fn poll<F>(&mut self, f: F, key: K) -> Poll<Result<V, E>>
pub fn poll<F>(&mut self, f: F, key: K) -> Poll<Result<V, E>>
Polls the result for key, spawning work if needed.
If this function returns Poll::Pending, call LocalPollAdapter::wait
to execute the work, then call this function again with the same key
to pick up the result.
Futures that complete immediately are not queued.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Returns the number of pending futures.
Auto Trait Implementations§
impl<'a, S, K, R> !Freeze for LocalPollAdapter<'a, S, K, R>
impl<'a, S, K, R> !RefUnwindSafe for LocalPollAdapter<'a, S, K, R>
impl<'a, S, K, R> !Send for LocalPollAdapter<'a, S, K, R>
impl<'a, S, K, R> !Sync for LocalPollAdapter<'a, S, K, R>
impl<'a, S, K, R> Unpin for LocalPollAdapter<'a, S, K, R>
impl<'a, S, K, R> UnsafeUnpin for LocalPollAdapter<'a, S, K, R>where
S: UnsafeUnpin,
impl<'a, S, K, R> !UnwindSafe for LocalPollAdapter<'a, S, K, R>
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
Mutably borrows from an owned value. Read more
§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>
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 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>
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<T> Pointable for T
impl<T> Pointable for T
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.