timer

package
v0.0.0-...-79ba347 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockMeter

type BlockMeter func() (uint32, error)

BlockMeter calculates block time interval dynamically.

func StaticBlockMeter

func StaticBlockMeter(d uint32) BlockMeter

StaticBlockMeter returns BlockMeters that always returns (d, nil).

type BlockTickHandler

type BlockTickHandler func()

BlockTickHandler is a callback of a certain block advance.

type BlockTimer

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

BlockTimer represents block timer.

It can tick the blocks and perform certain actions on block time intervals.

func NewBlockTimer

func NewBlockTimer(dur BlockMeter, h BlockTickHandler) *BlockTimer

NewBlockTimer creates a new BlockTimer.

Reset should be called before timer ticking.

func NewOneTickTimer

func NewOneTickTimer(dur BlockMeter, h BlockTickHandler) *BlockTimer

NewOneTickTimer creates a new BlockTimer that ticks only once.

Do not use delta handlers with pulse in this timer.

func (*BlockTimer) OnDelta

func (t *BlockTimer) OnDelta(mul, div uint32, h BlockTickHandler, opts ...DeltaOption)

OnDelta registers handler which is executed on (mul / div * BlockMeter()) block after basic interval reset.

If WithPulse option is provided, handler is executed (mul / div * BlockMeter()) block during base interval.

func (*BlockTimer) Reset

func (t *BlockTimer) Reset() error

Reset resets previous ticks of the BlockTimer.

Returns BlockMeter's error upon occurrence.

func (*BlockTimer) Tick

func (t *BlockTimer) Tick(h uint32)

Tick ticks one block in the BlockTimer.

Executes all callbacks which are awaiting execution at the new block.

type DeltaOption

type DeltaOption func(*deltaCfg)

DeltaOption is an option of delta-interval handler.

func WithPulse

func WithPulse() DeltaOption

WithPulse returns option to call delta-interval handler multiple times.

Jump to

Keyboard shortcuts

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