MCPcopy Create free account
hub / github.com/DoNewsCode/core / Make

Method Make

di/factory.go:36–54  ·  view source on GitHub ↗

Make creates an instance under the provided name. It an instance is already created and it is not nil, that instance is returned to the caller.

(name string)

Source from the content-addressed store, hash-verified

34// Make creates an instance under the provided name. It an instance is already
35// created and it is not nil, that instance is returned to the caller.
36func (f *Factory) Make(name string) (interface{}, error) {
37 var err error
38
39 conn, err, _ := f.group.Do(name, func() (interface{}, error) {
40 if slot, ok := f.cache.Load(name); ok {
41 return slot.(Pair).Conn, nil
42 }
43 slot, err := f.constructor(name)
44 if err != nil {
45 return nil, err
46 }
47 f.cache.Store(name, slot)
48 return slot.Conn, nil
49 })
50 if err != nil {
51 return nil, err
52 }
53 return conn, nil
54}
55
56// SubscribeReloadEventFrom subscribes to the reload events from dispatcher and then notifies the di
57// factory to clear its cache and shutdown all connections gracefully.

Callers 6

TestFactoryFunction · 0.95
TestFactory_nilCloserFunction · 0.95
TestFactory_WatchFunction · 0.95

Calls 1

DoMethod · 0.65

Tested by 6

TestFactoryFunction · 0.76
TestFactory_nilCloserFunction · 0.76
TestFactory_WatchFunction · 0.76