In a discussion about rate limiting an API I discovered that some of my code which uses such an API does not have a rate limiter (I thought I’d done something about that, but apparently not). So I’m rolling one. Fiddlier than I expected.
Anyway, one way to partly manage the typical “no more than N calls in a time frame” thing is a Semaphore
of size N representing in-play API calls and I’m wondering what happens when I have several things blocked awaiting capacity on the semaphore. Do they acquire it in any kind of first come first served fashion, or does an arbitrary waiter get the slot when it comes free?
I think I want my rate limiter to do first come first served and am wondering if I need some sort of queue as well as a semaphore.
The Semaphore
docs are silent on the matter, so I really ought to assume that there’s no implied queuing.