v0.0.0-...-e560ebb Latest Latest

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

Go to latest
Published: Jul 13, 2021 License: BSD-3-Clause Imports: 3 Imported by: 0



Package delay implements a delayable timer.



This section is empty.


This section is empty.


This section is empty.


type Timer

type Timer struct {
	// contains filtered or unexported fields

Timer is a delayable timer. The time cannot be delayed or reused after it fires.

func NewTimer

func NewTimer(t time.Time) *Timer

NewTimer returns a new Timer.

func WithTimer

func WithTimer(ctx context.Context, t time.Time) (context.Context, *Timer)

WithTimer returns a context that is canceled when a delayable timer fires.

Note that the returned timer's channel should not be used; only the Set/Stop methods should be used.

func (*Timer) C

func (t *Timer) C() <-chan time.Time

C returns the timer channel, like for time.Timer.

func (*Timer) Set

func (t *Timer) Set(new time.Time)

Set sets a new expiration time for the Timer. This method is safe to call concurrently.

Usually, the new time will be after the old time.

If the timer already fired, then this call does nothing.

func (*Timer) Stop

func (t *Timer) Stop()

Stop stops the timer from firing if it has not already. The timer cannot be reused afterward. This method is idempotent.

Jump to

Keyboard shortcuts

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