AkshatM / caprice

A Go client for RANDOM.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Respect the `advisoryDelay` returned from the API

AkshatM opened this issue · comments

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:

  1. Advisory delays are respected within a single-thread: all requests will wait for the specified interval after each other.
  2. 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.