Skip to content

Commit

Permalink
avoid Cancel/Reset/Delay operation after Close
Browse files Browse the repository at this point in the history
  • Loading branch information
singchia committed Nov 8, 2023
1 parent ed69786 commit b0e8064
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tick.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ type tick struct {

// TODO revision
func (t *tick) Reset(data interface{}) error {
t.tw.mtx.RLock()
defer t.tw.mtx.RUnlock()
if t.tw.twStatus != twStatusStarted {
return ErrTimerNotStarted
}

ch := make(chan *operationRet)
t.tw.operations <- &operation{
tick: t,
Expand All @@ -66,6 +72,9 @@ func (t *tick) Reset(data interface{}) error {
func (t *tick) Cancel() error {
t.tw.mtx.RLock()
defer t.tw.mtx.RUnlock()
if t.tw.twStatus != twStatusStarted {
return ErrTimerNotStarted
}

ch := make(chan *operationRet)
t.tw.operations <- &operation{
Expand All @@ -85,6 +94,11 @@ func (t *tick) Delay(d time.Duration) error {
if t.cyclically {
return ErrDelayOnCyclically
}
t.tw.mtx.RLock()
defer t.tw.mtx.RUnlock()
if t.tw.twStatus != twStatusStarted {
return ErrTimerNotStarted
}
ch := make(chan *operationRet)
t.tw.operations <- &operation{
tick: t,
Expand Down

0 comments on commit b0e8064

Please sign in to comment.