Rate limiting is an important mechanism for controlling resource utilization and maintaining quality of service. AngelScript can support rate limiting with threads, queues, and timers.
Running our program we would see the first batch of requests handled once every ~200 milliseconds as desired.
For the second batch of requests, we would serve the first 3 immediately because of the burstable rate limiting, then serve the remaining 2 with ~200ms delays each.
This example demonstrates how to implement basic rate limiting and bursty rate limiting in AngelScript. The concepts are similar to the original, but we’ve adapted them to use AngelScript’s threading and timing facilities. We’ve used a queue instead of a channel, and a token bucket algorithm for the bursty limiter instead of a buffered channel.