Skip to content

Commit

Permalink
add vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyu.zx committed Jun 20, 2022
1 parent 5dacc59 commit 5b3e02f
Show file tree
Hide file tree
Showing 405 changed files with 186,116 additions and 44 deletions.
4 changes: 0 additions & 4 deletions count.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ import (
"time"
)

/////////////////////////////////////////
// count watch
/////////////////////////////////////////

type CountWatch struct {
start time.Time
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/dubbogo/timer
go 1.15

require (
github.com/dubbogo/gost v1.10.4
github.com/dubbogo/gost v1.12.3
github.com/stretchr/testify v1.7.0
go.uber.org/atomic v1.7.0
)
643 changes: 636 additions & 7 deletions go.sum

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions sleep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
)

import (
"github.com/dubbogo/gost/log"
"github.com/stretchr/testify/assert"
"github.com/dubbogo/gost/log"
)

func TestNewTimerWheel(t *testing.T) {
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestAfter(t *testing.T) {
)
wheel = NewTimerWheel()

//Init()
// Init()

defer wheel.Stop()

Expand Down Expand Up @@ -174,6 +174,6 @@ func TestTimer_Stop(t *testing.T) {
time.Sleep(1e9)

time.Sleep(TimeSecondDuration(0.01))
//assert.Equalf(t, 0, defaultTimerWheel.TimerNumber(), "after stop")
// assert.Equalf(t, 0, defaultTimerWheel.TimerNumber(), "after stop")
time.Sleep(3e9)
}
2 changes: 1 addition & 1 deletion time.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func Time2UnixNano(t time.Time) int64 {
return t.UnixNano()
}

func GetEndtime(format string) time.Time {
func GetEndTime(format string) time.Time {
timeNow := time.Now()
switch format {
case "day":
Expand Down
42 changes: 18 additions & 24 deletions timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ import (
uatomic "go.uber.org/atomic"
)

var (
// nolint
ErrTimeChannelFull = errors.New("timer channel full")
// nolint
ErrTimeChannelClosed = errors.New("timer channel closed")
import (
gxchan "github.com/dubbogo/gost/container/chan"
gxlog "github.com/dubbogo/gost/log"
)

// nolint
var ErrTimeChannelClosed = errors.New("timer channel closed")

// InitDefaultTimerWheel initializes a default timer wheel
func InitDefaultTimerWheel() {
defaultTimerWheelOnce.Do(func() {
Expand Down Expand Up @@ -164,7 +165,7 @@ type TimerWheel struct {
slot [maxTimerLevel]*list.List // timer list

enable uatomic.Bool // timer ready or closed
timerQ chan *timerNodeAction // timer event notify channel
timerQ *gxchan.UnboundedChan // timer event notify channel

once sync.Once // for close ticker
ticker *time.Ticker // virtual atomic clock
Expand All @@ -177,7 +178,7 @@ func NewTimerWheel() *TimerWheel {
clock: atomic.LoadInt64(&curGxTime),
// in fact, the minimum time accuracy is 10ms.
ticker: time.NewTicker(time.Duration(minTickerInterval)),
timerQ: make(chan *timerNodeAction, timerNodeQueueSize),
timerQ: gxchan.NewUnboundedChan(timerNodeQueueSize),
}

w.enable.Store(true)
Expand All @@ -191,10 +192,8 @@ func NewTimerWheel() *TimerWheel {
go func() {
defer w.wg.Done()
var (
t time.Time
cFlag bool
nodeAction *timerNodeAction
qFlag bool
t time.Time
cFlag bool
)

LOOP:
Expand All @@ -214,11 +213,12 @@ func NewTimerWheel() *TimerWheel {
if ret == 0 {
w.run()
}
case nodeAction, qFlag = <-w.timerQ:
case node, qFlag := <-w.timerQ.Out():
if !qFlag {
break LOOP
}

nodeAction := node.(*timerNodeAction)
// just one w.timerQ channel to ensure the exec sequence of timer event.
switch {
case nodeAction.action == TimerActionAdd:
Expand Down Expand Up @@ -509,13 +509,10 @@ func (w *TimerWheel) AddTimer(f TimerFunc, typ TimerType, period time.Duration,
t := &Timer{w: w}
node := newTimerNode(f, typ, int64(period), arg)
select {
case w.timerQ <- &timerNodeAction{node: node, action: TimerActionAdd}:
case w.timerQ.In() <- &timerNodeAction{node: node, action: TimerActionAdd}:
t.ID = node.ID
return t, nil
default:
}

return nil, ErrTimeChannelFull
}

func (w *TimerWheel) deleteTimer(t *Timer) error {
Expand All @@ -524,12 +521,9 @@ func (w *TimerWheel) deleteTimer(t *Timer) error {
}

select {
case w.timerQ <- &timerNodeAction{action: TimerActionDel, node: &timerNode{ID: t.ID}}:
case w.timerQ.In() <- &timerNodeAction{action: TimerActionDel, node: &timerNode{ID: t.ID}}:
return nil
default:
}

return ErrTimeChannelFull
}

func (w *TimerWheel) resetTimer(t *Timer, d time.Duration) error {
Expand All @@ -538,12 +532,9 @@ func (w *TimerWheel) resetTimer(t *Timer, d time.Duration) error {
}

select {
case w.timerQ <- &timerNodeAction{action: TimerActionReset, node: &timerNode{ID: t.ID, period: int64(d)}}:
case w.timerQ.In() <- &timerNodeAction{action: TimerActionReset, node: &timerNode{ID: t.ID, period: int64(d)}}:
return nil
default:
}

return ErrTimeChannelFull
}

func sendTime(_ TimerID, t time.Time, arg interface{}) error {
Expand Down Expand Up @@ -571,6 +562,7 @@ func (w *TimerWheel) NewTimer(d time.Duration) *Timer {
return t
}

gxlog.CError("addTimer fail, err is %v", err)
close(c)
return nil
}
Expand Down Expand Up @@ -627,6 +619,7 @@ func (w *TimerWheel) NewTicker(d time.Duration) *Ticker {
return (*Ticker)(timer)
}

gxlog.CError("addTimer fail, err is %v", err)
close(c)
return nil
}
Expand All @@ -637,6 +630,7 @@ func (w *TimerWheel) TickFunc(d time.Duration, f func()) *Ticker {
if err == nil {
return (*Ticker)(t)
}
gxlog.CError("addTimer fail, err is %v", err)

return nil
}
Expand Down
8 changes: 4 additions & 4 deletions timer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ func TestUnixNano2Time(t *testing.T) {
}

func TestGetEndTime(t *testing.T) {
dayEndTime := GetEndtime("day")
dayEndTime := GetEndTime("day")
t.Logf("today end time %q", dayEndTime)

weekEndTime := GetEndtime("week")
weekEndTime := GetEndTime("week")
t.Logf("this week end time %q", weekEndTime)

monthEndTime := GetEndtime("month")
monthEndTime := GetEndTime("month")
t.Logf("this month end time %q", monthEndTime)

yearEndTime := GetEndtime("year")
yearEndTime := GetEndTime("year")
t.Logf("this year end time %q", yearEndTime)
}

Expand Down
15 changes: 15 additions & 0 deletions vendor/github.com/davecgh/go-spew/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

145 changes: 145 additions & 0 deletions vendor/github.com/davecgh/go-spew/spew/bypass.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5b3e02f

Please sign in to comment.