blocktime

package
v1.0.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewProvider

func NewProvider(opts ...options.Option[Clock]) module.Provider[*engine.Engine, clock.Clock]

NewProvider creates a new Clock provider with the given options.

Types

type Clock

type Clock struct {
	syncutils.RWMutex

	// Module embeds the required methods of the modular framework.
	module.Module
	// contains filtered or unexported fields
}

Clock implements the clock.Clock interface that sources its notion of time from accepted and confirmed blocks.

func New

func New(subModule module.Module, engine *engine.Engine, opts ...options.Option[Clock]) *Clock

func (*Clock) Accepted

func (c *Clock) Accepted() clock.RelativeTime

Accepted returns a notion of time that is anchored to the latest accepted block.

func (*Clock) Confirmed

func (c *Clock) Confirmed() clock.RelativeTime

Confirmed returns a notion of time that is anchored to the latest confirmed block.

func (*Clock) Reset

func (c *Clock) Reset(newTime time.Time)

Reset resets the time values tracked in the clock to the given time.

func (*Clock) Snapshot

func (c *Clock) Snapshot() *clock.Snapshot

type RelativeTime

type RelativeTime struct {
	// OnUpdated is triggered when the time is updated.
	OnUpdated *event.Event1[time.Time]
	// contains filtered or unexported fields
}

RelativeTime is a time value that monotonically advances with the system clock.

func NewRelativeTime

func NewRelativeTime() *RelativeTime

NewRelativeTime creates a new RelativeTime.

func (*RelativeTime) Advance

func (c *RelativeTime) Advance(newTime time.Time) (updated bool)

Advance advances the time value if the given time is larger than the current time (maintaining monotonicity of the relative time).

func (*RelativeTime) RelativeTime

func (c *RelativeTime) RelativeTime() time.Time

RelativeTime returns the time value after it has advanced with the system clock.

func (*RelativeTime) Reset

func (c *RelativeTime) Reset(newTime time.Time)

Reset resets the time value to the given time (resetting monotonicity of the relative time).

func (*RelativeTime) Set

func (c *RelativeTime) Set(newTime time.Time) (updated bool)

Set sets the time value if the given time is larger than the current time (resetting monotonicity of the relative time).

func (*RelativeTime) Time

func (c *RelativeTime) Time() time.Time

Time returns the original time value.

Jump to

Keyboard shortcuts

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