mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-02 03:17:37 +03:00
Remove unnecessary context wrappers
This commit is contained in:
parent
cdb9908442
commit
c9319a35ee
2 changed files with 11 additions and 6 deletions
|
@ -6,17 +6,17 @@ import (
|
|||
"github.com/sagernet/sing/service"
|
||||
)
|
||||
|
||||
// Deprecated: use service.ContextWith instead.
|
||||
func ManagerFromContext(ctx context.Context) Manager {
|
||||
return service.FromContext[Manager](ctx)
|
||||
}
|
||||
|
||||
// Deprecated: use service.ContextWith instead.
|
||||
func ContextWithManager(ctx context.Context, manager Manager) context.Context {
|
||||
return service.ContextWith[Manager](ctx, manager)
|
||||
}
|
||||
|
||||
// Deprecated: use WithDefaultManager instead.
|
||||
func ContextWithDefaultManager(ctx context.Context) context.Context {
|
||||
if service.FromContext[Manager](ctx) != nil {
|
||||
return ctx
|
||||
}
|
||||
return service.ContextWith[Manager](ctx, NewDefaultManager(ctx))
|
||||
return WithDefaultManager(ctx)
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"github.com/sagernet/sing/common/atomic"
|
||||
"github.com/sagernet/sing/common/x/list"
|
||||
"github.com/sagernet/sing/service"
|
||||
)
|
||||
|
||||
type defaultManager struct {
|
||||
|
@ -18,16 +19,20 @@ type defaultManager struct {
|
|||
callbacks list.List[Callback]
|
||||
}
|
||||
|
||||
func NewDefaultManager(ctx context.Context) Manager {
|
||||
func WithDefaultManager(ctx context.Context) context.Context {
|
||||
if service.FromContext[Manager](ctx) != nil {
|
||||
return ctx
|
||||
}
|
||||
devicePauseChan := make(chan struct{})
|
||||
networkPauseChan := make(chan struct{})
|
||||
close(devicePauseChan)
|
||||
close(networkPauseChan)
|
||||
return &defaultManager{
|
||||
manager := &defaultManager{
|
||||
ctx: ctx,
|
||||
devicePause: devicePauseChan,
|
||||
networkPause: networkPauseChan,
|
||||
}
|
||||
return service.ContextWith[Manager](ctx, manager)
|
||||
}
|
||||
|
||||
func (d *defaultManager) DevicePause() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue