Skip to main content

Group

Struct Group 

Source
pub struct Group<K, T, E, S = RandomState> { /* private fields */ }
Expand description

Group represents a class of work and creates a space in which units of work can be executed with duplicate suppression.

Implementations§

Source§

impl<K, T, E, S> Group<K, T, E, S>
where S: Default,

Source

pub fn new() -> Group<K, T, E, S>

Create a new Group to do work with.

Source§

impl<K, T, E, S> Group<K, T, E, S>
where T: Clone, K: Hash + Eq, S: BuildHasher,

Source

pub async fn work<Q, F>(&self, key: &Q, fut: F) -> Result<T, Option<E>>
where Q: Hash + Eq + ?Sized + Send + Sync + ToOwned<Owned = K>, F: Future<Output = Result<T, E>> + Send, K: Borrow<Q>,

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.
  • If the leader returns an error, owner call returns error, others will return Err(None).
Source

pub async fn purge_stale(&self)

Remove completed entries left by promoted leaders after leader-drop recovery.

When a leader is dropped and a follower takes over, the promoted leader leaves its result cached in the map so that late-arriving retriers can read it. These entries are automatically replaced by the next fresh work call for the same key, but if no new call arrives, they persist.

This method removes all such completed entries. It is safe to call at any time, though calling it while leader-drop recovery is actively in progress for a key may cause a late retrier to re-execute the work function for that key (a benign but redundant execution).

Source

pub async fn work_no_retry<Q, F>( &self, key: &Q, fut: F, ) -> Result<T, GroupWorkError<E>>
where Q: Hash + Eq + ?Sized + Send + Sync + ToOwned<Owned = K>, F: Future<Output = Result<T, E>> + Send, K: Borrow<Q>,

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.
  • If the leader returns an error, owner call returns error, others will return Err(GroupWorkError::LeaderFailed).
  • If the leader drops, the call will return Err(GroupWorkError::LeaderDropped).

Trait Implementations§

Source§

impl<K, T, E, S> Debug for Group<K, T, E, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K, T, E, S> Default for Group<K, T, E, S>
where S: Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<K, T, E, S = RandomState> !Freeze for Group<K, T, E, S>

§

impl<K, T, E, S = RandomState> !RefUnwindSafe for Group<K, T, E, S>

§

impl<K, T, E, S> Send for Group<K, T, E, S>
where S: Send, K: Send, T: Send + Sync,

§

impl<K, T, E, S> Sync for Group<K, T, E, S>
where S: Send, K: Send, T: Send + Sync,

§

impl<K, T, E, S> Unpin for Group<K, T, E, S>
where S: Unpin, K: Unpin,

§

impl<K, T, E, S> UnwindSafe for Group<K, T, E, S>
where K: UnwindSafe, S: 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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.