base/common/src/main/com/thesett/common/throttle/TokenBucketThrottle.java
public long timeToThrottleNanos()
    {
        // Work out how long ago the last throttle query was.
        long currentTimeNanos = System.nanoTime();
        long delay = currentTimeNanos - lastTimeNanos;

        // Regenerate the tokens allowed since the last query.
        float numTokens = (delay * 1.0e9f) * targetRate;

        tokenCount -= numTokens;

        if (tokenCount < 0f)
        {
            tokenCount = 0f;
        }

        // Update the last time stamp for next time around.
        lastTimeNanos = currentTimeNanos;

        // Check if there are tokens available to consume, and consume one if so.
        if (tokenCount <= (depth - 1.0))
        {
            tokenCount += 1.0;

            return 0;
        }
        else
        {
            // There are no tokens to consume, so return an estimate of how long it will take to generate one token.
            return (long) (1.0e9 / targetRate);
        }
    }
public long timeToThrottleNanos()
    {
        // Work out how long ago the last throttle query was.
        long currentTimeNanos = System.nanoTime();
        long delay = currentTimeNanos - lastTimeNanos;

        // Regenerate the tokens allowed since the last query.
        float numTokens = (delay * 1.0e9f) * targetRate;

        tokenCount -= numTokens;

        if (tokenCount < 0f)
        {
            tokenCount = 0f;
        }

        // Update the last time stamp for next time around.
        lastTimeNanos = currentTimeNanos;

        // Check if there are tokens available to consume, and consume one if so.
        if (tokenCount <= (depth - 1.0))
        {
            tokenCount += 1.0;

            return 0;
        }
        else
        {
            // There are no tokens to consume, so return an estimate of how long it will take to generate one token.
            return (long) (1.0e9 / targetRate);
        }
    }
public long timeToThrottleNanos ( ) { // Work out how long ago the last throttle query was. long currentTimeNanos = System . nanoTime ( ) ; long delay = currentTimeNanos - lastTimeNanos ; // Regenerate the tokens allowed since the last query. float numTokens = ( delay * 1.0e9f ) * targetRate ; tokenCount -= numTokens ; if ( tokenCount < 0f ) { tokenCount = 0f ; } // Update the last time stamp for next time around. lastTimeNanos = currentTimeNanos ; // Check if there are tokens available to consume, and consume one if so. if ( tokenCount <= ( depth - 1.0 ) ) { tokenCount += 1.0 ; return 0 ; } else { // There are no tokens to consume, so return an estimate of how long it will take to generate one token. return ( long ) ( 1.0e9 / targetRate ) ; } }
Checks but does not enforce the throttle rate. When this method is called, it checks if a length of time greater
than that equal to the inverse of the throttling rate has passed since it was last called and returned <tt>
true</tt>. If the length of time still to elapse to the next throttle allow point is zero or less, this method
will return a negative value, if there is still time to pass until the throttle allow point, this method will
return a positive value indicating the amount of time still to pass. A thread can wait for that period of time
before rechecking the throttle condition.

@return The length of time since or still to elaps to the next throttle allow point. A negative value indicates
that the throttle time has passed and a positive time indicates that there is still time to pass before
it is reached. The units are in nanoseconds.
Checks but does not enforce the throttle rate . When this method is called it checks if a length of time greater than that equal to the inverse of the throttling rate has passed since it was last called and returned <tt > true< / tt > . If the length of time still to elapse to the next throttle allow point is zero or less this method will return a negative value if there is still time to pass until the throttle allow point this method will return a positive value indicating the amount of time still to pass . A thread can wait for that period of time before rechecking the throttle condition .