func (r *Reservation) CancelAt(now time.Time) {
	if !r.ok {
		return
	}
	r.lim.mu.Lock()
	defer r.lim.mu.Unlock()
	if r.lim.limit == Inf || r.tokens == 0 || r.timeToAct.Before(now) {
		return
	}
	restoreTokens := float64(r.tokens) - r.limit.tokensFromDuration(r.lim.lastEvent.Sub(r.timeToAct))
	if restoreTokens <= 0 {
		return
	}
	now, _, tokens := r.lim.advance(now)
	tokens += restoreTokens
	if burst := float64(r.lim.burst); tokens > burst {
		tokens = burst
	}
	r.lim.last = now  
	r.lim.tokens = tokens
	if r.timeToAct == r.lim.lastEvent {
		prevEvent := r.timeToAct.Add(r.limit.durationFromTokens(float64(-r.tokens)))
		if !prevEvent.Before(now) {
			r.lim.lastEvent = prevEvent
		}
	}
	return
}
CancelAt indicates that the reservation holder will not perform the reserved action
and reverses the effects of this Reservation on the rate limit as much as possible,
considering that other reservations may have already been made.
package rate
import (
	"context"
	"fmt"
	"math"
	"sync"
	"time"
)
type Limit float64
const Inf = Limit(math.MaxFloat64)
func Every(interval time.Duration) Limit {
	if interval <= 0 {
		return Inf
	}
	return 1 / Limit(interval.Seconds())
}
type Limiter struct {
	limit Limit
	burst int  
	mu     sync.Mutex
	tokens float64  
	last time.Time
	lastEvent time.Time
}
func (lim *Limiter) Limit() Limit {
	lim.mu.Lock()
	defer lim.mu.Unlock()
	return lim.limit
}
func (lim *Limiter) Burst() int {
	return lim.burst
}
func NewLimiter(r Limit, b int) *Limiter {
	return &Limiter{
		limit: r,
		burst: b,
	}
}
func (lim *Limiter) Allow() bool {
	return lim.AllowN(time.Now(), 1)
}
func (lim *Limiter) AllowN(now time.Time, n int) bool {
	return lim.reserveN(now, n, 0).ok
}
type Reservation struct {
	ok        bool
	lim       *Limiter
	tokens    int
	timeToAct time.Time
	limit Limit
}
func (r *Reservation) OK() bool {
	return r.ok
}
func (r *Reservation) Delay() time.Duration {
	return r.DelayFrom(time.Now())
}
const InfDuration = time.Duration(1<<63 - 1)
func (r *Reservation) DelayFrom(now time.Time) time.Duration {
	if !r.ok {
		return InfDuration
	}
	delay := r.timeToAct.Sub(now)
	if delay < 0 {
		return 0
	}
	return delay
}
func (r *Reservation) Cancel() {
	r.CancelAt(time.Now())
	return
}