Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added method to get current capacity of rate limiter for given algorithm #1

Merged
merged 1 commit into from
Nov 22, 2020

Conversation

norberttech
Copy link
Member

This PR makes something I would call the final API shape

    /**
     * Record next hit, throws an extension where there are no available hits left according to the selected algorithm.
     *
     * @throws RateLimitException
     */
    public function hit(string $id) : void

    /**
     * Estimate time required to the next hit. If current capacity is greater than 0, time will be 0.
     */
    public function estimate(string $id) : TimeUnit

    /**
     * Returns current capacity according to the selected algorithm, when there are no available hits left, it will return 0.
     * Use RateLimiter::estimate method to find out when next hit will be possible.
     */
    public function capacity(string $id) : int

    /**
     * Try to record next hit, in case of rate limit exception take the cooldown time and sleep current process.
     */
    public function throttle(string $id, Process $process) : void

@norberttech norberttech merged commit b1602e7 into aeon-php:1.x Nov 22, 2020
@norberttech norberttech added this to the 0.1.0 milestone Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant