spiceJ/core/src/main/java/at/borkowski/spicej/streams/RateHelper.java
public int take(int n) {
      int lenToTake;
      while (true) {
         int stored = spent.get();
         lenToTake = Math.min(n, thingsPerTick - stored);
         if (stored >= thingsPerTick)
            sleep();
         else if (spent.compareAndSet(stored, stored + lenToTake))
            break;
      }
      timewiseAvailable -= lenToTake;
      return lenToTake;
   }
public int take(int n) {
      int lenToTake;
      while (true) {
         int stored = spent.get();
         lenToTake = Math.min(n, thingsPerTick - stored);
         if (stored >= thingsPerTick)
            sleep();
         else if (spent.compareAndSet(stored, stored + lenToTake))
            break;
      }
      timewiseAvailable -= lenToTake;
      return lenToTake;
   }
public int take ( int n ) { int lenToTake ; while ( true ) { int stored = spent . get ( ) ; lenToTake = Math . min ( n , thingsPerTick - stored ) ; if ( stored >= thingsPerTick ) sleep ( ) ; else if ( spent . compareAndSet ( stored , stored + lenToTake ) ) break ; } timewiseAvailable -= lenToTake ; return lenToTake ; }
Takes several things (eg. bytes). This method blocks until at least one
thing can be used according to the current rate and prescaling settings.

This method returns at least 1.

@param n
up to how many things to take
@return the number of things that have been taken, at least 1
Takes several things ( eg . bytes ) . This method blocks until at least one thing can be used according to the current rate and prescaling settings .