timers

package
v0.49.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2025 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EpochTicks

type EpochTicks struct {
	NewEpochTicks []Tick
	DeltaTicks    []SubEpochTick
}

EpochTicks defines start epoch timers and epoch subtimers for NewTimers. Must be initialized with NewTimers.

type EpochTimers

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

EpochTimers is a timer that executes any predefined Tick or SubEpochTick based on chain information provided via EpochTimers.UpdateTime. EpochTicks are both block- and time-based, see EpochTimers.Reset and EpochTimers.UpdateTime.

func NewTimers

func NewTimers(tt EpochTicks) *EpochTimers

NewTimers inits EpochTimers. If [EpochTicks.DeltaTicks] is not empty, none of them must have zero [SubEpochTick.EpochDiv].

func (*EpochTimers) Reset

func (et *EpochTimers) Reset(lastTick, curr, dur uint64)

Reset must be called every time EpochTimers user receives information about new epoch event. lastTick must be block's timestamp that contains new epoch event; curr must be the last known block's timestamp; dur is an actual epoch duration in milliseconds.

func (*EpochTimers) UpdateTime

func (et *EpochTimers) UpdateTime(curr uint64)

UpdateTime must be called every time EpochTimers user receives information about chain's new block acceptance. curr must be just-arrived block's timestamp.

type SubEpochTick

type SubEpochTick struct {
	Tick     Tick   // handle to execute
	EpochMul uint32 // X: X/Y of epoch in seconds
	EpochDiv uint32 // Y: X/Y of epoch in seconds
}

SubEpochTick is like a Tick but will be executed every epoch at: epochDuration * [SubEpochTick.EpochMul] / [SubEpochTick.EpochDiv]. [SubEpochTick.EpochDiv] must not be zero.

type Tick

type Tick func()

Tick is a handler that must be executed every time any of EpochTimers expires.

Jump to

Keyboard shortcuts

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