Refactor lifecycle to scoped cleanup

This commit is contained in:
世界
2026-10-09 12:36:03 +08:00
parent a364ff4794
commit a691a44023
115 changed files with 1595 additions and 2030 deletions
+4 -1
View File
@@ -73,7 +73,10 @@ func (s *Selector) Network() []string {
return selected.Network()
}
func (s *Selector) Start() error {
func (s *Selector) Start(stage adapter.StartStage, scope *adapter.Scope) error {
if stage != adapter.StartStateStart {
return nil
}
for i, tag := range s.tags {
detour, loaded := s.outbound.Outbound(tag)
if !loaded {
+2 -7
View File
@@ -71,7 +71,7 @@ func NewURLTest(ctx context.Context, router adapter.Router, logger log.ContextLo
return outbound, nil
}
func (s *URLTest) Start(stage adapter.StartStage) error {
func (s *URLTest) Start(stage adapter.StartStage, scope *adapter.Scope) error {
switch stage {
case adapter.StartStateStart:
outbounds := make([]adapter.Outbound, 0, len(s.tags))
@@ -89,16 +89,11 @@ func (s *URLTest) Start(stage adapter.StartStage) error {
s.group = group
case adapter.StartStateStarted:
s.group.PostStart()
scope.Add(s.group.Close)
}
return nil
}
func (s *URLTest) Close() error {
return common.Close(
common.PtrOrNil(s.group),
)
}
func (s *URLTest) Now() string {
if s.group.selectedOutboundTCP != nil {
return s.group.selectedOutboundTCP.Tag()