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>
impl<K, T, E, S> Group<K, T, E, S>
Sourcepub async fn work<Q, F>(&self, key: &Q, fut: F) -> Result<T, Option<E>>
pub async fn work<Q, F>(&self, key: &Q, fut: F) -> Result<T, Option<E>>
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).
Sourcepub async fn purge_stale(&self)
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).
Sourcepub async fn work_no_retry<Q, F>(
&self,
key: &Q,
fut: F,
) -> Result<T, GroupWorkError<E>>
pub async fn work_no_retry<Q, F>( &self, key: &Q, fut: F, ) -> Result<T, GroupWorkError<E>>
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).