timeutil

package
v0.9.7 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 2 Imported by: 7

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sleep added in v0.9.7

func Sleep(done <-chan struct{}, duration time.Duration) bool

Sleep is like time.Sleep, but supports context.Context and more by short-circuiting on done. Returns true, unless short-circuited by done.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/smartcontractkit/chainlink-common/pkg/timeutil"
)

func main() {
	ctx := context.Background()
	if !timeutil.Sleep(ctx.Done(), time.Second) {
		log.Fatal("context done")
	}
	fmt.Printf("Slept for %s\n", time.Second)

}
Output:

Slept for 1s

Types

type JitterPct

type JitterPct float64

JitterPct is a percent by which to scale a duration up or down. For example, 0.1 will result in +/- 10%.

func (JitterPct) Apply

func (p JitterPct) Apply(d time.Duration) time.Duration

type Ticker

type Ticker struct {
	C <-chan time.Time
	// contains filtered or unexported fields
}

Ticker is like time.Ticker, but with a variable period.

func NewTicker

func NewTicker(nextDur func() time.Duration) *Ticker

NewTicker returns a started Ticker which calls nextDur for each period. Ticker.Stop should be called to prevent goroutine leaks.

func (*Ticker) Reset

func (t *Ticker) Reset()

Reset starts a new period.

func (*Ticker) Stop

func (t *Ticker) Stop()

Stop permanently stops the Ticker. It cannot be Reset.

Jump to

Keyboard shortcuts

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