challengetimer

package
v0.132.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package challengetimer measures active solving time, excluding pauses.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidState indicates an operation outside its allowed lifecycle.
	ErrInvalidState = errors.New("challengetimer: invalid state")
	// ErrInvalidReason indicates an undefined pause reason.
	ErrInvalidReason = errors.New("challengetimer: invalid pause reason")
)

Functions

This section is empty.

Types

type PauseReason

type PauseReason string

PauseReason identifies an independent reason to exclude time.

const (
	ReasonManual   PauseReason = "manual"
	ReasonHidden   PauseReason = "hidden"
	ReasonQuery    PauseReason = "query"
	ReasonPlayback PauseReason = "playback"
)

type Snapshot

type Snapshot struct {
	State        State
	ActiveMillis int64
	Hints        int
	Retries      int
	Assisted     bool
	PauseReasons []PauseReason
}

Snapshot is an independent view of a timer at one instant.

type State

type State string

State describes a timer's lifecycle.

const (
	StateReady    State = "ready"
	StateRunning  State = "running"
	StatePaused   State = "paused"
	StateFinished State = "finished"
)

type Timer

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

Timer is safe for concurrent use. Create one with New; do not copy it. The supplied clock runs under the timer's lock and must not call its methods.

func New

func New(now func() time.Time) *Timer

New creates a ready timer. A nil clock selects time.Now.

func (*Timer) Finish

func (t *Timer) Finish() (Snapshot, error)

Finish freezes elapsed time and counters, clearing all pause reasons. Repeated calls return the same result without observing the clock.

func (*Timer) Hint

func (t *Timer) Hint() error

Hint records assistance without imposing a time penalty.

func (*Timer) Pause

func (t *Timer) Pause(reason PauseReason) error

Pause adds a reason to pause. Adding an existing reason is idempotent.

func (*Timer) Reset

func (t *Timer) Reset()

Reset restores the ready state and clears the clock epoch and all counters.

func (*Timer) Resume

func (t *Timer) Resume(reason PauseReason) error

Resume removes a pause reason. Removing an absent reason is idempotent.

func (*Timer) Retry

func (t *Timer) Retry() error

Retry records a retry without imposing a time penalty.

func (*Timer) Snapshot

func (t *Timer) Snapshot() Snapshot

Snapshot returns the current state and an independently owned sorted slice.

func (*Timer) Start

func (t *Timer) Start() error

Start begins a fresh timer's clock epoch.

Jump to

Keyboard shortcuts

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