ticker

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2025 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Example (TickerImpl_Tick)
ticker := New[int]()
defer ticker.Stop()

ticks := ticker.Ticks()

ticker.Tick(42)
next, stop := iter.Pull(ticks)

fmt.Println(next())
stop()
Output:

42 true

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Restartable

type Restartable interface {
	Startable
	Stoppable
}

type Startable

type Startable interface {
	Start()
}

type Stoppable

type Stoppable interface {
	Stop()
}

type Tickable

type Tickable[TickType any] interface {
	Ticks() iter.Seq[TickType]
	Tick(TickType) Waitable
}

type Ticker

type Ticker[TickType any] interface {
	Tickable[TickType]
	Stoppable
	Waitable
}

func New

func New[TickType any]() Ticker[TickType]

type TimeTicker

type TimeTicker interface {
	Tickable[time.Time]
	Restartable
	Waitable
	Reset(time.Duration)
}

func NewTimer

func NewTimer(d time.Duration) TimeTicker

NewTimer creates a ticker that ticks on a timer. The timer is started on the first call to Ticks. If d == 0, the ticker internal timer is not started, and no ticks are dispatched.

Example

This example illustrates the use of the ticker, that ticks every second during 2.5 seconds, and stops.

timer := NewTimer(time.Second)
time.AfterFunc(2500*time.Millisecond, timer.Stop)

startTime := time.Now()
for tick := range timer.Ticks() {
	fmt.Println(tick.Sub(startTime).Round(time.Second))
}
Output:

0s
1s
2s

type Waitable

type Waitable interface {
	Wait()
}

Jump to

Keyboard shortcuts

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