File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,17 +6,17 @@ import (
66 "github.com/sagernet/sing/service"
77)
88
9+ // Deprecated: use service.ContextWith instead.
910func ManagerFromContext (ctx context.Context ) Manager {
1011 return service.FromContext [Manager ](ctx )
1112}
1213
14+ // Deprecated: use service.ContextWith instead.
1315func ContextWithManager (ctx context.Context , manager Manager ) context.Context {
1416 return service .ContextWith [Manager ](ctx , manager )
1517}
1618
19+ // Deprecated: use WithDefaultManager instead.
1720func ContextWithDefaultManager (ctx context.Context ) context.Context {
18- if service.FromContext [Manager ](ctx ) != nil {
19- return ctx
20- }
21- return service .ContextWith [Manager ](ctx , NewDefaultManager (ctx ))
21+ return WithDefaultManager (ctx )
2222}
Original file line number Diff line number Diff line change 66
77 "github.com/sagernet/sing/common/atomic"
88 "github.com/sagernet/sing/common/x/list"
9+ "github.com/sagernet/sing/service"
910)
1011
1112type defaultManager struct {
@@ -18,16 +19,20 @@ type defaultManager struct {
1819 callbacks list.List [Callback ]
1920}
2021
21- func NewDefaultManager (ctx context.Context ) Manager {
22+ func WithDefaultManager (ctx context.Context ) context.Context {
23+ if service.FromContext [Manager ](ctx ) != nil {
24+ return ctx
25+ }
2226 devicePauseChan := make (chan struct {})
2327 networkPauseChan := make (chan struct {})
2428 close (devicePauseChan )
2529 close (networkPauseChan )
26- return & defaultManager {
30+ manager := & defaultManager {
2731 ctx : ctx ,
2832 devicePause : devicePauseChan ,
2933 networkPause : networkPauseChan ,
3034 }
35+ return service .ContextWith [Manager ](ctx , manager )
3136}
3237
3338func (d * defaultManager ) DevicePause () {
You can’t perform that action at this time.
0 commit comments