func (tb *TokenBucket) Availible() int64 {
	tb.tokenMutex.Lock()
	defer tb.tokenMutex.Unlock()
	return tb.avail
}
Availible returns how many tokens are availible in the bucket.
package bucket
import (
	"container/list"
	"fmt"
	"sync"
	"time"
)
type TokenBucket struct {
	interval          time.Duration
	ticker            *time.Ticker
	tokenMutex        *sync.Mutex
	waitingQuqueMutex *sync.Mutex
	waitingQuque      *list.List
	cap               int64
	avail             int64
}
type waitingJob struct {
	ch        chan struct{}
	need      int64
	use       int64
	abandoned bool
}
func New(interval time.Duration, cap int64) *TokenBucket {
	if interval < 0 {
		panic(fmt.Sprintf("ratelimit: interval %v should > 0", interval))
	}
	if cap < 0 {
		panic(fmt.Sprintf("ratelimit: capability %v should > 0", cap))
	}
	tb := &TokenBucket{
		interval:          interval,
		tokenMutex:        &sync.Mutex{},
		waitingQuqueMutex: &sync.Mutex{},
		waitingQuque:      list.New(),
		cap:               cap,
		avail:             cap,
		ticker:            time.NewTicker(interval),
	}
	go tb.adjustDaemon()
	return tb
}
func (tb *TokenBucket) Capability() int64 {
	return tb.cap
}