timer

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is a stopwatch

Service increments the currentTime anytime the attached TickerInterface ticks and running is true. Service uses Go's monotonic clock to generate diffs between the startTime and ticker current time to increment currentTime

func NewService

func NewService(t TickerInterface) (*Service, chan time.Duration)

NewService returns a Service and a channel that sends the currentTime at approximately 60 FPS.

func (*Service) GetCurrentTime

func (s *Service) GetCurrentTime() time.Duration

GetCurrentTime allows public read access to the currentTime

func (*Service) GetCurrentTimeFormatted

func (s *Service) GetCurrentTimeFormatted() string

GetCurrentTimeFormatted returns a frontend friendly string representing the current accumulated time.

func (*Service) IsRunning

func (s *Service) IsRunning() bool

IsRunning returns the running state of the Timer

func (*Service) Pause

func (s *Service) Pause()

Pause freezes the current time, and sets the running state to false so ticker updates stop accumulating.

func (*Service) Reset

func (s *Service) Reset()

Reset sets the running state to false, stopping the ticker updates from accumulating then sets the current time to 0.

func (*Service) Run

func (s *Service) Run()

func (*Service) Start

func (s *Service) Start()

Start marks the current time for the monotonic clock and sets the running state to true

func (*Service) Startup

func (s *Service) Startup(ctx context.Context)

Startup receives a context.Context from Wails.Run

type Ticker

type Ticker struct {
	// contains filtered or unexported fields
}

Ticker wraps time.Ticker to allow DI for testing

func NewTicker

func NewTicker(d time.Duration) *Ticker

NewTicker constructor

func (Ticker) Ch

func (t Ticker) Ch() <-chan time.Time

Ch provides read access to the channel that the ticker uses to signal ticks.

func (Ticker) Stop

func (t Ticker) Stop()

Stop terminates ticks.

type TickerInterface

type TickerInterface interface {
	Ch() <-chan time.Time
	Stop()
}

TickerInterface wraps time.Ticker to allow DI for testing

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL