timer

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: MIT, MIT, BSD-2-Clause Imports: 2 Imported by: 0

README

timer

Build Status GoDoc

Golang timer with start and pause

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Timer

type Timer struct {
	C <-chan time.Time
	// contains filtered or unexported fields
}

The Timer type represents a single event. When the Timer expires, the current time will be sent on C, unless the Timer was created by AfterFunc. A Timer must be created with NewTimer or AfterFunc.

func AfterFunc

func AfterFunc(d time.Duration, f func()) *Timer

AfterFunc waits after calling its Start method for the duration to elapse and then calls f in its own goroutine. It returns a Timer that can be used to cancel the call using its Stop method, or pause using its Pause method

func NewTimer

func NewTimer(d time.Duration) *Timer

NewTimer creates a new Timer. It returns a Timer that can be used to cancel the call using its Stop method, or pause using its Pause method

func (*Timer) Pause

func (t *Timer) Pause() bool

Pause pauses current timer until Start method will be called. Next Start call will wait rest of duration.

func (*Timer) Paused

func (t *Timer) Paused() bool

Paused returns true if the timer is in idle state, either because Start() hasn't been called yet or because Pause() was called.

func (*Timer) SetTimeLeft

func (t *Timer) SetTimeLeft(d time.Duration) bool

SetTimeLeft adjusts the point in time the timer will fire to duration d from now. It returns false if the timer already expired, true otherwise.

func (*Timer) Start

func (t *Timer) Start() bool

Start starts Timer that will send the current time on its channel after at least duration d.

func (*Timer) Stop

func (t *Timer) Stop() bool

Stop prevents the Timer from firing. It returns true if the call stops the timer, false if the timer has already expired or been stopped. Stop does not close the channel, to prevent a read from the channel succeeding incorrectly.

func (*Timer) TimeLeft

func (t *Timer) TimeLeft() time.Duration

TimeLeft returns the duration left to run before the timer expires. TimeLeft is safe to be called on a nil timer and will return 0 in that case.

Jump to

Keyboard shortcuts

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