MCPcopy
hub / github.com/SurgeDM/Surge / NewLifecycleManager

Function NewLifecycleManager

internal/processing/manager.go:85–115  ·  view source on GitHub ↗
(addFunc AddDownloadFunc, addWithIDFunc AddDownloadWithIDFunc, isNameActive ...IsNameActiveFunc)

Source from the content-addressed store, hash-verified

83}
84
85func NewLifecycleManager(addFunc AddDownloadFunc, addWithIDFunc AddDownloadWithIDFunc, isNameActive ...IsNameActiveFunc) *LifecycleManager {
86 // Snapshot settings once so enqueue can still make routing decisions even if
87 // a later disk read fails or the caller never opens the settings UI.
88 settings, err := config.LoadSettings()
89 if err != nil {
90 settings = config.DefaultSettings()
91 }
92
93 var activeCheck IsNameActiveFunc
94 if len(isNameActive) > 0 {
95 activeCheck = isNameActive[0]
96 }
97
98 probeCap := defaultMaxConcurrentProbes
99 if settings != nil && config.Resolve[int](settings.Network.MaxConcurrentProbes) > 0 {
100 probeCap = config.Resolve[int](settings.Network.MaxConcurrentProbes)
101 }
102 sem := make(chan struct{}, probeCap)
103 for i := 0; i < probeCap; i++ {
104 sem <- struct{}{}
105 }
106
107 return &LifecycleManager{
108 settings: settings,
109 settingsRefreshedAt: time.Now(),
110 addFunc: addFunc,
111 addWithIDFunc: addWithIDFunc,
112 isNameActive: activeCheck,
113 probeSem: sem,
114 }
115}
116
117// SetEngineHooks injects dependencies the manager needs to interact with the broader system
118// (like the download worker pool or the event system) without causing cyclic dependency graphs.

Calls 2

LoadSettingsFunction · 0.92
DefaultSettingsFunction · 0.92