rename sharedcalls to singleflight (#1017)

This commit is contained in:
Kevin Wan
2021-09-09 18:06:27 +08:00
committed by GitHub
parent f070d447ef
commit 5cc9eb0de4
11 changed files with 49 additions and 39 deletions

View File

@@ -9,16 +9,16 @@ import (
// A ResourceManager is a manager that used to manage resources.
type ResourceManager struct {
resources map[string]io.Closer
sharedCalls SharedCalls
lock sync.RWMutex
resources map[string]io.Closer
singleFlight SingleFlight
lock sync.RWMutex
}
// NewResourceManager returns a ResourceManager.
func NewResourceManager() *ResourceManager {
return &ResourceManager{
resources: make(map[string]io.Closer),
sharedCalls: NewSharedCalls(),
resources: make(map[string]io.Closer),
singleFlight: NewSingleFlight(),
}
}
@@ -39,7 +39,7 @@ func (manager *ResourceManager) Close() error {
// GetResource returns the resource associated with given key.
func (manager *ResourceManager) GetResource(key string, create func() (io.Closer, error)) (io.Closer, error) {
val, err := manager.sharedCalls.Do(key, func() (interface{}, error) {
val, err := manager.singleFlight.Do(key, func() (interface{}, error) {
manager.lock.RLock()
resource, ok := manager.resources[key]
manager.lock.RUnlock()