udoprog / leaky-bucket

A token-based rate limiter based on the leaky bucket algorithm.
Apache License 2.0
93 stars 10 forks source link

remove the need for a background coordinator #12

Closed udoprog closed 3 years ago

udoprog commented 3 years ago

This allows for operating a rate limiter entirely without having to spawn a background coordinating task.

It works by instead designating one of the waiting tasks as the core, making it responsible to wake up any waiting tasks as appropriate (including itself) once enough tokens are available. The core responsibility can then migrate between waiting tasks.

Part of this implementation currently hits issues around the soundness of self-referential generators.

See the module level documentation for more information.