Skip to main content

IdempotencyStore

Trait IdempotencyStore 

Source
pub trait IdempotencyStore: Send + Sync {
    // Required methods
    fn begin<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Outcome, DataError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn complete<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        response: Value,
    ) -> Pin<Box<dyn Future<Output = Result<(), DataError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn get<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<IdempotencyRecord>, DataError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

A store that deduplicates operations by idempotency key.

Required Methods§

Source

fn begin<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Outcome, DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Atomically claim key if it is free, otherwise report its current state.

Returns Outcome::New when this caller wins the claim (a record is created InProgress), Outcome::InProgress if another claim is live, or Outcome::Completed with the stored response if the work is done.

Source

fn complete<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, response: Value, ) -> Pin<Box<dyn Future<Output = Result<(), DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Mark key’s operation completed and store response for future replays.

§Errors

Returns DataError::Idempotency if the key was never claimed.

Source

fn get<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<IdempotencyRecord>, DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetch the raw record for key, if any.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§