package hostfiles import ( "sort" "time" ) // queue holds, per path, the time by which its first unpublished // modification must be published. A later modification of a path already // waiting does not move its deadline, so a file written without pause is // still published every period. type queue struct { d time.Duration due map[string]time.Time } func newQueue(d time.Duration) *queue { return &queue{d: d, due: map[string]time.Time{}} } func (q *queue) Touch(rel string, now time.Time) { if _, waiting := q.due[rel]; !waiting { q.due[rel] = now.Add(q.d) } } // Due removes and returns every path whose deadline has arrived. func (q *queue) Due(now time.Time) []string { var out []string for rel, at := range q.due { if !at.After(now) { out = append(out, rel) delete(q.due, rel) } } sort.Strings(out) return out }