clock

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CancelToken

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

CancelToken is returned by Register and allows the caller to cancel the timer.

func (*CancelToken) Cancel

func (t *CancelToken) Cancel()

Cancel removes the timer from the clock. Safe to call multiple times.

type Clock

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

Clock manages periodic timers that fire callbacks and publish TimeEvents to the msgbus. All methods are called from the single dispatch thread.

func NewClock

func NewClock(bus *msgbus.MsgBus) *Clock

NewClock creates a new Clock attached to the given MsgBus.

func (*Clock) Register

func (c *Clock) Register(startNs, intervalNs uint64, callback func(event.TimeEvent)) *CancelToken

Register creates a periodic timer that first fires at startNs, then every intervalNs nanoseconds. The callback is invoked directly from the dispatch thread during Tick(). A TimeEvent is also published to the msgbus. Returns a CancelToken to stop the timer.

func (*Clock) Tick

func (c *Clock) Tick(nowNs uint64)

Tick checks all registered timers against nowNs and fires any that are due. For each due timer it calls the callback and publishes a TimeEvent. If multiple intervals have elapsed, each tick is fired individually.

func (*Clock) TimerCount

func (c *Clock) TimerCount() int

TimerCount returns the number of active timers.

Jump to

Keyboard shortcuts

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