Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LayerConv ¶
type LayerConv struct {
// contains filtered or unexported fields
}
LayerConv is a converter between time to layer ID struct.
func (LayerConv) LayerToTime ¶
LayerToTime returns the time of the provided layer.
type LayerConverter ¶
type LayerConverter interface { TimeToLayer(time.Time) types.LayerID LayerToTime(types.LayerID) time.Time }
LayerConverter provides conversions from time to layer and vice versa.
type LayerTimer ¶
LayerTimer is a channel of LayerIDs Subscribers will receive the ticked layer through such channel.
type Ticker ¶
type Ticker struct { LayerConverter // layer conversions provider // contains filtered or unexported fields }
Ticker is the struct responsible for notifying that a layer has been ticked to subscribers.
func NewTicker ¶
func NewTicker(c Clock, lc LayerConverter, opts ...TickerOption) *Ticker
NewTicker returns a new instance of ticker.
func (*Ticker) AwaitLayer ¶
AwaitLayer returns a channel that will be signaled when layer id layerID was ticked by the clock, or if this layer has passed while sleeping. it does so by closing the returned channel.
func (*Ticker) GetCurrentLayer ¶
GetCurrentLayer gets the current layer.
func (*Ticker) Notify ¶
Notify notifies all the subscribers with the current layer. if the tick time has passed by more than sendTickThreshold, notify is skipped and errMissedTickTime is returned. if some subscribers were not listening, they are skipped and errMissedTicks/number of missed ticks is returned. notify may be skipped also for non-monotonic tick. (the clock can go backward when the system clock gets calibrated).
func (*Ticker) StartNotifying ¶
func (t *Ticker) StartNotifying()
StartNotifying starts the clock notifying.
func (Ticker) Subscribe ¶
func (s Ticker) Subscribe() LayerTimer
Subscribe returns a channel on which the subscriber will be notified when a new layer starts.
func (Ticker) Unsubscribe ¶
func (s Ticker) Unsubscribe(ch LayerTimer)
Unsubscribe removed subscriber channel ch from notification list.
type TimeClock ¶
type TimeClock struct { *Ticker // contains filtered or unexported fields }
TimeClock is the struct holding a real clock.
func NewClock ¶
func NewClock(c Clock, tickInterval time.Duration, genesisTime time.Time, logger log.Log) *TimeClock
NewClock return TimeClock struct that notifies tickInterval has passed.
func (*TimeClock) GetGenesisTime ¶
GetGenesisTime returns at which time this clock has started (used to calculate current tick).
func (*TimeClock) GetInterval ¶ added in v0.1.6
GetInterval returns the time interval between clock ticks.
func (TimeClock) Subscribe ¶
func (s TimeClock) Subscribe() LayerTimer
Subscribe returns a channel on which the subscriber will be notified when a new layer starts.
func (TimeClock) Unsubscribe ¶
func (s TimeClock) Unsubscribe(ch LayerTimer)
Unsubscribe removed subscriber channel ch from notification list.