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)
| 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. |
| 36 | func (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. |