Algorithm-RateLimiter-TokenBucket

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

    if ($can_send > 0) {
        # Send $can_send bytes
    }
}
```

# DESCRIPTION

`Algorithm::RateLimiter::TokenBucket` implements the [token bucket](https://en.wikipedia.org/wiki/Token_bucket)
algorithm for rate limiting. It is specifically designed to be **loop-agnostic**, meaning it does not manage its own
timers or background threads. Instead, you "drive" it by calling `tick( )` with the amount of time that has passed.

This makes it ideal for integration into event loops (like [IO::Async](https://metacpan.org/pod/IO%3A%3AAsync) or [Mojo::IOLoop](https://metacpan.org/pod/Mojo%3A%3AIOLoop)) or high-performance network
applications.

# METHODS

## `new( limit =` $bytes\_per\_second )>

Creates a new limiter. `limit` is optional and defaults to 0 (unlimited).

lib/Algorithm/RateLimiter/TokenBucket.pod  view on Meta::CPAN

        my $can_send = $limiter->consume( 16384 );
        if ($can_send > 0) {
            # Send $can_send bytes
        }
    }

=head1 DESCRIPTION

C<Algorithm::RateLimiter::TokenBucket> implements the L<token bucket|https://en.wikipedia.org/wiki/Token_bucket>
algorithm for rate limiting. It is specifically designed to be B<loop-agnostic>, meaning it does not manage its own
timers or background threads. Instead, you "drive" it by calling C<tick( )> with the amount of time that has passed.

This makes it ideal for integration into event loops (like L<IO::Async> or L<Mojo::IOLoop>) or high-performance network
applications.

=head1 METHODS

=head2 C<new( limit => $bytes_per_second )>

Creates a new limiter. C<limit> is optional and defaults to 0 (unlimited).



( run in 0.853 second using v1.01-cache-2.11-cpan-acebb50784d )