MCPcopy Index your code
hub / github.com/DoNewsCode/core / SubscribeReloadEventFrom

Method SubscribeReloadEventFrom

di/factory.go:58–76  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
58func (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.
79func (f *Factory) List() map[string]Pair {

Callers 9

provideMongoFactoryFunction · 0.95
TestFactory_WatchFunction · 0.95
provideRedisFactoryFunction · 0.95
provideFactoryFunction · 0.95
provideDBFactoryFunction · 0.95
provideFactoryFunction · 0.95
provideEsFactoryFunction · 0.95
provideKafkaFactoryFunction · 0.80

Calls 4

ListenFunction · 0.92
DeleteMethod · 0.80
DoMethod · 0.65
SubscribeMethod · 0.65

Tested by 2

TestFactory_WatchFunction · 0.76