Clear function to clear things on reparse

This commit is contained in:
Simon Martens
2025-01-07 20:13:08 +01:00
parent f2fd9f9c0a
commit 6cfed94ff6
2 changed files with 8 additions and 4 deletions

View File

@@ -27,9 +27,6 @@ func (r *Resolver[T]) Add(typeName, refID string, item Resolved[T]) {
}
func (r *Resolver[T]) Get(typeName, refID string) ([]Resolved[T], error) {
r.mu.Lock()
defer r.mu.Unlock()
if typeIndex, exists := r.index[typeName]; exists {
if items, ok := typeIndex[refID]; ok {
return items, nil
@@ -38,3 +35,10 @@ func (r *Resolver[T]) Get(typeName, refID string) ([]Resolved[T], error) {
}
return nil, fmt.Errorf("no index exists for type '%s'", typeName)
}
func (r *Resolver[T]) Clear() {
r.mu.Lock()
defer r.mu.Unlock()
r.index = make(map[string]map[string][]Resolved[T])
}