github.com/larrabee/ratelimit@v1.0.6-0.20191102113931-712217ec4fdc/fake_bucket.go (about)

     1  package ratelimit
     2  
     3  import (
     4  	"math"
     5  	"time"
     6  )
     7  
     8  type FakeBucket struct{}
     9  
    10  // NewBucket returns a new fake token bucket.
    11  func NewFakeBucket() *FakeBucket {
    12  	return &FakeBucket{}
    13  }
    14  
    15  // Wait takes count tokens from the bucket, waiting until they are available.
    16  func (tb *FakeBucket) Wait(count int64) {}
    17  
    18  // WaitMaxDuration is like Wait.
    19  func (tb *FakeBucket) WaitMaxDuration(count int64, maxWait time.Duration) bool {
    20  	return true
    21  }
    22  
    23  // Take takes count tokens from the bucket without blocking. It returns
    24  // the time that the caller should wait until the tokens are actually
    25  // available.
    26  //
    27  // Note that if the request is irrevocable - there is no way to return
    28  // tokens to the bucket once this method commits us to taking them.
    29  func (tb *FakeBucket) Take(count int64) time.Duration {
    30  	return 0
    31  }
    32  
    33  // TakeMaxDuration is like Take, except that
    34  // it will only take tokens from the bucket if the wait
    35  // time for the tokens is no greater than maxWait.
    36  //
    37  // If it would take longer than maxWait for the tokens
    38  // to become available, it does nothing and reports false,
    39  // otherwise it returns the time that the caller should
    40  // wait until the tokens are actually available, and reports
    41  // true.
    42  func (tb *FakeBucket) TakeMaxDuration(count int64, maxWait time.Duration) (time.Duration, bool) {
    43  	return 0, true
    44  }
    45  
    46  // TakeAvailable takes up to count immediately available tokens from the
    47  // bucket. It returns the number of tokens removed, or zero if there are
    48  // no available tokens. It does not block.
    49  func (tb *FakeBucket) TakeAvailable(count int64) int64 {
    50  	return math.MaxInt64
    51  }
    52  
    53  // Available returns the number of available tokens.
    54  func (tb *FakeBucket) Available() int64 {
    55  	return math.MaxInt64
    56  }
    57  
    58  // Capacity returns the capacity that the bucket was created with.
    59  func (tb *FakeBucket) Capacity() int64 {
    60  	return math.MaxInt64
    61  }
    62  
    63  // Rate returns the fill rate of the bucket, in tokens per second.
    64  func (tb *FakeBucket) Rate() float64 {
    65  	return math.MaxFloat64
    66  }