timer

package module
v0.0.0-...-7cbd720 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2019 License: MIT Imports: 2 Imported by: 0

README

timer-core

Goals

Timer core is supposed to be an easy to use go module for providing accurate, simple, stable and tested timers. It is mainly developed to replace the MarathonTools timer code and make it reusable for other projects.

Subtimers

Subtimers provide an easy way to time multiple things which are related to the main running timer (like players in a speedrun marathon).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// AllowContinueAfterStop will allow resumeing the timer after it has been stopped
	AllowResumeAfterStop bool
	// ContinueCountingWhenStopped sets how the timer behaves after it is resumed after stopping
	// if set to true the timer will continue counting in the background. For example timer is stopped after 1s and then resumed after 2s.
	// The timer will now continue counting from 3s instead from 1s. This option exists for accidental stopping of the timer
	ContinueCountingWhenStopped bool
	// StopOnSubtimersFinish will stop the timer when all subtimers are set to stop
	StopOnSubtimersStop bool
}

Config allows configuring various settings when creating a new timer

type State

type State int

State describes the different Timerstates

const (
	// Reset represents a timer which has been initialized but is currently not running
	Reset State = iota
	// Running represents a running timer
	Running
	// Paused represents a paused timer
	Paused
	// Stopped represents a stopped timer
	Stopped
)

type Timer

type Timer struct {

	// public
	State   State
	Updates chan time.Duration
	// contains filtered or unexported fields
}

Timer is the main struct holding all relevant data

func New

func New() *Timer

New initializes and returns a new timer with

func (*Timer) AddSubTimer

func (t *Timer) AddSubTimer(id int) error

AddSubTimer adds a timer with an id to the subtimer pool id has to be unique and can only be added when timer is in reset state

func (*Timer) PauseTimer

func (t *Timer) PauseTimer() error

PauseTimer timer pauses the timer only possible when in Running state

func (*Timer) ResetTimer

func (t *Timer) ResetTimer() error

ResetTimer resets the timer to it's default state only possible when in Stopped state

func (*Timer) ResumeTimer

func (t *Timer) ResumeTimer() error

ResumeTimer resumes the timer from a paused state only possible when in Paused or Stopped state

func (*Timer) SetUpdateInterval

func (t *Timer) SetUpdateInterval(updateInterval int) error

SetUpdateInterval sets a new updateInterval for the timer Only works when timer is stopped. Setting 0 for updateInterval sets it back to the default

func (*Timer) StartTimer

func (t *Timer) StartTimer() error

StartTimer starts the timer only possible when timer is in Reset state

func (*Timer) StopSubTimer

func (t *Timer) StopSubTimer(id int) (time.Duration, error)

StopSubTimer will stop a specific subtimer only works when subtimer and timer are running

func (*Timer) StopTimer

func (t *Timer) StopTimer() error

StopTimer stops the timer only possible when in Running state

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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