mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-08-22 14:38:34 +00:00
Timer: prevent creating redundant check task
This commit is contained in:
parent
33272a0499
commit
eba1f7258e
@ -56,20 +56,22 @@ func (t *ActivityTimer) SetTimeout(timeout time.Duration) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.Lock()
|
||||||
|
defer t.Unlock()
|
||||||
|
if t.onTimeout == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
checkTask := &task.Periodic{
|
checkTask := &task.Periodic{
|
||||||
Interval: timeout,
|
Interval: timeout,
|
||||||
Execute: t.check,
|
Execute: t.check,
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Lock()
|
|
||||||
|
|
||||||
if t.checkTask != nil {
|
if t.checkTask != nil {
|
||||||
t.checkTask.Close()
|
t.checkTask.Close()
|
||||||
}
|
}
|
||||||
t.checkTask = checkTask
|
t.checkTask = checkTask
|
||||||
t.Update()
|
t.Update()
|
||||||
common.Must(checkTask.Start())
|
common.Must(checkTask.Start())
|
||||||
t.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CancelAfterInactivity(ctx context.Context, cancel context.CancelFunc, timeout time.Duration) *ActivityTimer {
|
func CancelAfterInactivity(ctx context.Context, cancel context.CancelFunc, timeout time.Duration) *ActivityTimer {
|
||||||
|
Loading…
Reference in New Issue
Block a user