aboutsummaryrefslogtreecommitdiff
path: root/internal/engine/tick.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/engine/tick.go')
-rw-r--r--internal/engine/tick.go28
1 files changed, 20 insertions, 8 deletions
diff --git a/internal/engine/tick.go b/internal/engine/tick.go
index 8c64cdd..e2e7343 100644
--- a/internal/engine/tick.go
+++ b/internal/engine/tick.go
@@ -20,14 +20,15 @@ type subscriber struct {
}
type Engine struct {
- tickMu sync.Mutex // serializes manual ticks and successive ticker runs
- mu sync.Mutex
- subscribers map[uint64]*subscriber
- nextID uint64
- ticker *time.Ticker
- running bool
- stopCh chan struct{}
- loopDone chan struct{}
+ tickMu sync.Mutex // serializes manual ticks and successive ticker runs
+ mu sync.Mutex
+ subscribers map[uint64]*subscriber
+ nextID uint64
+ ticker *time.Ticker
+ running bool
+ tickLengthMs int
+ stopCh chan struct{}
+ loopDone chan struct{}
}
func New() *Engine {
@@ -36,6 +37,16 @@ func New() *Engine {
}
}
+// TickLengthMilliseconds reports the configured cadence for countdown displays.
+func (e *Engine) TickLengthMilliseconds() int {
+ e.mu.Lock()
+ defer e.mu.Unlock()
+ if e.tickLengthMs == 0 {
+ return 600
+ }
+ return e.tickLengthMs
+}
+
func (e *Engine) Subscribe(interval int, cb Callback) uint64 {
e.mu.Lock()
defer e.mu.Unlock()
@@ -64,6 +75,7 @@ func (e *Engine) Start(tickLengthMs int) {
if tickLengthMs < 50 {
tickLengthMs = 50
}
+ e.tickLengthMs = tickLengthMs
e.ticker = time.NewTicker(time.Duration(tickLengthMs) * time.Millisecond)
e.stopCh = make(chan struct{})
// Capture this run's resources. A quick Stop/Start must not make the