新增rpc自定义超时

This commit is contained in:
duanhf2012
2023-07-13 16:42:23 +08:00
parent 85a8ec58e5
commit 4b84d9a1d5
8 changed files with 251 additions and 113 deletions

View File

@@ -7,6 +7,7 @@ import (
"reflect"
"runtime"
"time"
"sync/atomic"
)
// ITimer
@@ -29,7 +30,7 @@ type OnAddTimer func(timer ITimer)
// Timer
type Timer struct {
Id uint64
cancelled bool //是否关闭
cancelled int32 //是否关闭
C chan ITimer //定时器管道
interval time.Duration // 时间间隔(用于循环定时器)
fireTime time.Time // 触发时间
@@ -171,12 +172,12 @@ func (t *Timer) GetInterval() time.Duration {
}
func (t *Timer) Cancel() {
t.cancelled = true
atomic.StoreInt32(&t.cancelled,1)
}
// 判断定时器是否已经取消
func (t *Timer) IsActive() bool {
return !t.cancelled
return atomic.LoadInt32(&t.cancelled) == 0
}
func (t *Timer) GetName() string {