8 type throttleEnt struct {
9 last time.Time // last attempt that was allowed
12 type throttle struct {
14 seen map[string]*throttleEnt
20 // Check checks whether there have been too many recent attempts with
21 // the given uuid, and returns true if it's OK to attempt [again] now.
22 func (t *throttle) Check(uuid string) bool {
26 t.setupOnce.Do(t.setup)
28 defer t.updated.Broadcast()
30 ent, ok := t.seen[uuid]
32 t.seen[uuid] = &throttleEnt{last: time.Now()}
35 if time.Since(ent.last) < t.hold {
42 func (t *throttle) setup() {
43 t.seen = make(map[string]*throttleEnt)
46 for range time.NewTicker(t.hold).C {
48 for uuid, ent := range t.seen {
49 if time.Since(ent.last) >= t.hold {
53 // don't bother cleaning again until the next update