MCPcopy Index your code
hub / github.com/foxcpp/maddy / GetOpen

Method GetOpen

framework/resource/singleton.go:23–43  ·  view source on GitHub ↗
(key string, open func() (T, error))

Source from the content-addressed store, hash-verified

21}
22
23func (s *Singleton[T]) GetOpen(key string, open func() (T, error)) (T, error) {
24 s.lock.Lock()
25 defer s.lock.Unlock()
26
27 existing, ok := s.resources[key]
28 if ok {
29 s.log.DebugMsg("resource reused", "key", key)
30 return existing, nil
31 }
32
33 res, err := open()
34 if err != nil {
35 var empty T
36 return empty, err
37 }
38
39 s.log.DebugMsg("new resource", "key", key)
40 s.resources[key] = res
41
42 return res, nil
43}
44
45func (s *Singleton[T]) CloseUnused(isUsed func(key string) bool) error {
46 s.lock.Lock()

Callers

nothing calls this directly

Calls 1

DebugMsgMethod · 0.80

Tested by

no test coverage detected