private double waitFor(double permits,long t){
  long begin=t;
  writeRate.lock();
  try {
    while (permits > 0) {
      long nanosPerPermit=this.nanosPerPermit;
      long done=t + (long)(permits * nanosPerPermit);
      long now=System.nanoTime();
      if (done > now) {
        rateChanged.awaitNanos(done - now);
        now=System.nanoTime();
      }
      double permitsElapsed=(now - t) / (double)nanosPerPermit;
      permits-=permitsElapsed;
      t=now;
    }
  }
 catch (  InterruptedException e) {
  }
 finally {
    writeRate.unlock();
  }
  return t - begin;
}

private double waitFor ( double permits , long t ) { long begin = t ; writeRate . lock ( ) ; try { while ( permits > 0 ) { long nanosPerPermit = this . nanosPerPermit ; long done = t + ( long ) ( permits * nanosPerPermit ) ; long now = System . nanoTime ( ) ; if ( done > now ) { rateChanged . awaitNanos ( done - now ) ; now = System . nanoTime ( ) ; } double permitsElapsed = ( now - t ) / ( double ) nanosPerPermit ; permits -= permitsElapsed ; t = now ; } } catch ( InterruptedException e ) { } finally { writeRate . unlock ( ) ; } return t - begin ; }
waits until the specified number of permits have passed
