Respect the `advisoryDelay` returned from the API
AkshatM opened this issue · comments
Akshat Mahajan commented
Currently, Caprice does not wait for a recommended interval between synchronous requests as requested by the API. This violates the Usage Guidelines.
We should ensure that:
- Advisory delays are respected within a single-thread: all requests will wait for the specified interval after each other.
- Advisory delays are respected in a thread safe manner: all requests across all threads will wait for the minimum specified interval.
One way to accomplish this is to calculate a timestamp from the advisory delay and the current timestamp and store it in a read-and-write mutex.
A thread will only make a request if the current time exceeds the timestamp value, and will update the mutex with a new timestamp including the minimum allowable delay before ceding access to anyone.
Instructions for committing a fix
- Write passing tests that can validate this behaviour.
- Submit a PR.