pub struct Group<T, E>where
T: ResultType + 'static,
E: ResultError,{ /* 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<T, E> Group<T, E>where
T: ResultType + 'static,
E: ResultError + 'static,
impl<T, E> Group<T, E>where
T: ResultType + 'static,
E: ResultError + 'static,
Sourcepub async fn work(
&self,
key: &str,
fut: impl TaskFuture<T, E> + 'static,
) -> (Result<T, SingleflightError<E>>, bool)
pub async fn work( &self, key: &str, fut: impl TaskFuture<T, E> + 'static, ) -> (Result<T, SingleflightError<E>>, bool)
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 second return value indicates whether the call is the owner.
On error, the owner will receive the original error returned from the function as a SingleflightError::InternalError, all waiters will receive a copy of the error message wrapped in a SingleflightError::WaiterInternalError. This is due to the fact that most error types don’t implement Clone (e.g. anyhow::Error) and thus we can’t clone the original error for all the waiters.
Sourcepub async fn work_dump_caller_info(
&self,
key: &str,
fut: impl TaskFuture<T, E> + 'static,
) -> Result<T, SingleflightError<E>>
pub async fn work_dump_caller_info( &self, key: &str, fut: impl TaskFuture<T, E> + 'static, ) -> Result<T, SingleflightError<E>>
Like work but only returns the result, dumps the bool result value