Struct singleflight_async::SingleFlight
source · [−]pub struct SingleFlight<T> { /* private fields */ }
Expand description
SingleFlight represents a class of work and creates a space in which units of work can be executed with duplicate suppression.
Implementations
sourceimpl<T> SingleFlight<T>
impl<T> SingleFlight<T>
sourcepub fn work_with_owned_key<F, Fut>(
&self,
key: Cow<'static, str>,
func: F
) -> impl Future<Output = T> where
F: FnOnce() -> Fut,
Fut: Future<Output = T>,
T: Clone,
pub fn work_with_owned_key<F, Fut>(
&self,
key: Cow<'static, str>,
func: F
) -> impl Future<Output = T> where
F: FnOnce() -> Fut,
Fut: Future<Output = T>,
T: Clone,
Execute and return the value for a given function, making sure that only one operation is in-flight at a given moment. If a duplicate call comes in, that caller will wait until the original call completes and return the same value.
The key is a Owned key. The performance will be slightly better than work
.
sourcepub fn work<F, Fut>(&self, key: &str, func: F) -> impl Future<Output = T> where
F: FnOnce() -> Fut,
Fut: Future<Output = T>,
T: Clone,
pub fn work<F, Fut>(&self, key: &str, func: F) -> impl Future<Output = T> where
F: FnOnce() -> Fut,
Fut: Future<Output = T>,
T: Clone,
Execute and return the value for a given function, making sure that only one operation is in-flight at a given moment. If a duplicate call comes in, that caller will wait until the original call completes and return the same value.
Trait Implementations
sourceimpl<T: Debug> Debug for SingleFlight<T>
impl<T: Debug> Debug for SingleFlight<T>
Auto Trait Implementations
impl<T> !RefUnwindSafe for SingleFlight<T>
impl<T> Send for SingleFlight<T> where
T: Send + Sync,
impl<T> Sync for SingleFlight<T> where
T: Send + Sync,
impl<T> Unpin for SingleFlight<T>
impl<T> !UnwindSafe for SingleFlight<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more