Skip to content

proposal: time: allow a user callback for dropped ticks #35480

@gobwas

Description

@gobwas

Hi there!

There is a known time.Ticker behavior when ticks are being dropped if user can't read from time.Ticker.C channel in time.

For some kind of "real-time" applications it may be useful to know that ticks are dropped to react somehow on such events.

I suppose it could be allowed just by extending time.Ticker struct with an optional exported callback field (and little tweaks of time.sendTime use):

const interval = time.Second

t := time.NewTicker(interval)
t.OnTickDrop = func() {
    log.Printf("warning: dropping %s tick", interval)
}

Without such feature users need to implement their own tick scheduler with very similar implementation to time's internals.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions