Does a Semaphore queue? I'm expecting not

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.

The source shows that Semaphore has an internal Condition variable. The condition.wait method appends to a queue of waiters. The condition.notify method activates and removes the oldest waiter at position 0. It implements firstcome firstserved. This is not documented.

Thanks. I’ll proceed on that basis then for now. Probably try to put
some simple check to fire if it becomes unqueued in the future.