gaato/discord/cooldown does not have a README file

    CooldownStore

    pub(open) trait CooldownStore {
    async fn try_acquire(Self, key : String, window_ms~ : Int64) -> CooldownDecision
    }

    Storage for command cooldown windows. Implementations own their clock.

    CooldownDecision

    pub(all) enum CooldownDecision {
    Acquired
    Active(retry_after_ms~ : Int64)
    } derive(Eq,
    Debug
    )

    The result of attempting to start a cooldown window.

    InMemoryCooldownStore

    pub struct InMemoryCooldownStore {
    // private fields
    }

    In-process fixed windows with lazy cleanup of expired keys.

    InMemoryCooldownStore::InMemoryCooldownStore

    fn InMemoryCooldownStore::InMemoryCooldownStore(now? : () -> Int64) -> InMemoryCooldownStore

    Create an empty store, optionally supplying a clock for deterministic tests.

    async test {
    let store = @cooldown.InMemoryCooldownStore(now=() => 1_000L)
    assert_eq(store.try_acquire("1:ping|global", window_ms=10_000L), Acquired)
    assert_eq(
    store.try_acquire("1:ping|global", window_ms=10_000L),
    Active(retry_after_ms=10_000L),
    )
    }

    InMemoryCooldownStore::try_acquire

    async fn InMemoryCooldownStore::try_acquire(self : InMemoryCooldownStore, key : String, window_ms~ : Int64) -> CooldownDecision

    Source Files