Files
lone-services/services/ws/internal/svc/serviceContext.go
T
2026-10-15 09:23:07 +08:00

32 lines
487 B
Go

package svc
import (
"context"
"lone-services/services/ws/internal/config"
)
type ServiceContext struct {
Config config.Config
Hub *Hub
cancel context.CancelFunc
}
func NewServiceContext(c config.Config) *ServiceContext {
h := NewHub()
ctx, cancel := context.WithCancel(context.Background())
go NewSubscriber(h).Run(ctx)
return &ServiceContext{
Config: c,
Hub: h,
cancel: cancel,
}
}
func (s *ServiceContext) Close() {
if s.cancel != nil {
s.cancel()
}
}