mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-06-08 20:19:12 -04:00
clean up dns package
This commit is contained in:
@@ -53,8 +53,7 @@ func (t *ActivityTimer) run() {
|
||||
}
|
||||
}
|
||||
|
||||
func CancelAfterInactivity(ctx context.Context, timeout time.Duration) (context.Context, *ActivityTimer) {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
func CancelAfterInactivity(ctx context.Context, cancel context.CancelFunc, timeout time.Duration) *ActivityTimer {
|
||||
timer := &ActivityTimer{
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
@@ -63,5 +62,5 @@ func CancelAfterInactivity(ctx context.Context, timeout time.Duration) (context.
|
||||
}
|
||||
timer.timeout <- timeout
|
||||
go timer.run()
|
||||
return ctx, timer
|
||||
return timer
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ import (
|
||||
func TestActivityTimer(t *testing.T) {
|
||||
assert := With(t)
|
||||
|
||||
ctx, timer := CancelAfterInactivity(context.Background(), time.Second*5)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
timer := CancelAfterInactivity(ctx, cancel, time.Second*5)
|
||||
time.Sleep(time.Second * 6)
|
||||
assert(ctx.Err(), IsNotNil)
|
||||
runtime.KeepAlive(timer)
|
||||
@@ -22,7 +23,8 @@ func TestActivityTimer(t *testing.T) {
|
||||
func TestActivityTimerUpdate(t *testing.T) {
|
||||
assert := With(t)
|
||||
|
||||
ctx, timer := CancelAfterInactivity(context.Background(), time.Second*10)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
timer := CancelAfterInactivity(ctx, cancel, time.Second*10)
|
||||
time.Sleep(time.Second * 3)
|
||||
assert(ctx.Err(), IsNil)
|
||||
timer.SetTimeout(time.Second * 1)
|
||||
|
||||
Reference in New Issue
Block a user