Skip to content

Commit

Permalink
fixed ticker to respect custom interval. Default time.Millisecond on …
Browse files Browse the repository at this point in the history
…0 updateInterval
  • Loading branch information
JocularMarrow committed Jun 18, 2024
1 parent c103a21 commit 8b35a6e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions clock.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ func New(multiplier float64) *QuickTick {
//
// Use this function if you need to customize the clock's update frequency and starting time.
func NewCustom(startTime time.Time, multiplier float64, updateInterval time.Duration) *QuickTick {
if updateInterval == 0 {
updateInterval = time.Millisecond
}

ac := &QuickTick{
multiplier: multiplier,
tickerInterval: updateInterval,
Expand Down Expand Up @@ -101,6 +105,10 @@ func NewCtx(ctx context.Context, multiplier float64) *QuickTick {
//
// Use this function if you need to customize the clock's update frequency and starting time, and also want to control the clock's lifecycle with a context.
func NewCustomCtx(ctx context.Context, startTime time.Time, multiplier float64, updateInterval time.Duration) *QuickTick {
if updateInterval == 0 {
updateInterval = time.Millisecond
}

ac := &QuickTick{
multiplier: multiplier,
tickerInterval: updateInterval,
Expand All @@ -115,7 +123,7 @@ func NewCustomCtx(ctx context.Context, startTime time.Time, multiplier float64,

// Start clock
func (ac *QuickTick) run() {
ticker := time.NewTicker(time.Millisecond)
ticker := time.NewTicker(ac.tickerInterval)
defer ticker.Stop()

for {
Expand All @@ -130,7 +138,7 @@ func (ac *QuickTick) run() {

// Start clock with context
func (ac *QuickTick) runWithContext(ctx context.Context) {
ticker := time.NewTicker(time.Millisecond)
ticker := time.NewTicker(ac.tickerInterval)
defer ticker.Stop()

for {
Expand Down

0 comments on commit 8b35a6e

Please sign in to comment.