load_state.go 855 B

123456789101112131415161718192021222324252627282930313233
  1. package entities
  2. import "sync"
  3. var (
  4. loadAttemptedMu sync.RWMutex
  5. loadAttempted = map[string]bool{}
  6. )
  7. // MarkEntityLoadAttempted records that OliveTin has tried to load this entity
  8. // type from its entity file (successfully or not).
  9. func MarkEntityLoadAttempted(entityName string) {
  10. if entityName == "" {
  11. return
  12. }
  13. loadAttemptedMu.Lock()
  14. defer loadAttemptedMu.Unlock()
  15. loadAttempted[entityName] = true
  16. }
  17. // HasEntityLoadAttempted reports whether a load has been attempted for the entity type.
  18. func HasEntityLoadAttempted(entityName string) bool {
  19. loadAttemptedMu.RLock()
  20. defer loadAttemptedMu.RUnlock()
  21. return loadAttempted[entityName]
  22. }
  23. // ResetEntityLoadAttempts clears load-attempt tracking (used by tests).
  24. func ResetEntityLoadAttempts() {
  25. loadAttemptedMu.Lock()
  26. defer loadAttemptedMu.Unlock()
  27. loadAttempted = map[string]bool{}
  28. }