<commit_before><commit_msg>implement leaseManager<commit_after>package lease

import "time"

type Resource interface {
	ID() string
}

type LeaseManager interface {
	// lease the resource r for duration d.  When the lease expires, invoke `revoke`
	// a lease can be refreshed by calling Lease() again on the same resource
	Lease(r Resource, d time.Duration, revoke func())
	// return the resource r.
	Return(r Resource)
}

type leaseManager struct {
	timers map[string]*time.Timer
}

func NewLeaseManager() LeaseManager {
	return &leaseManager{
		timers: make(map[string]*time.Timer),
	}
}

func (l *leaseManager) Lease(r Resource, d time.Duration, revoke func()) {
	timer := time.AfterFunc(d, revoke)
	// cancel the old timer and add the new one
	if t, ok := c.timers[r.ID()]; ok {
		t.Stop()
	}
	c.timers[r.ID()] = timer
}

func (l *leaseManager) Return(r Resource) {
	if t, ok := c.timers[r.ID()]; ok {
		t.Stop()
	}
}
{'fraction_non_alphanumeric': 0.13137893593919653, 'fraction_numerical': 0.0, 'mean_word_length': 4.093922651933702, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6118066', 'n_tokens_mistral': 324, 'n_tokens_neox': 321, 'n_words': 103}