SubscribeReloadEventFrom subscribes to the reload events from dispatcher and then notifies the di factory to clear its cache and shutdown all connections gracefully.
(dispatcher contract.Dispatcher)
| 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. |
| 58 | func (f *Factory) SubscribeReloadEventFrom(dispatcher contract.Dispatcher) { |
| 59 | if dispatcher == nil { |
| 60 | return |
| 61 | } |
| 62 | f.reloadOnce.Do(func() { |
| 63 | dispatcher.Subscribe(events.Listen(events.OnReload, func(ctx context.Context, event interface{}) error { |
| 64 | f.cache.Range(func(key, value interface{}) bool { |
| 65 | defer f.cache.Delete(key) |
| 66 | pair := value.(Pair) |
| 67 | if pair.Closer == nil { |
| 68 | return true |
| 69 | } |
| 70 | pair.Closer() |
| 71 | return true |
| 72 | }) |
| 73 | return nil |
| 74 | })) |
| 75 | }) |
| 76 | } |
| 77 | |
| 78 | // List lists created instance in the factory. |
| 79 | func (f *Factory) List() map[string]Pair { |