/go-cticker

A clock based ticker library for golang

Primary LanguageGoBSD 2-Clause "Simplified" LicenseBSD-2-Clause

go-cticker Go Report Card License GoDoc Build Status

go-cticker is a Go library that provides a ticker which ticks according to wall clock and is reliable under clock drift and clock adjustments; that is if you ask it to tick on the minute it will ensure that it does so even if the underlying clock is inaccurate or gets adjusted.

Features

  • Reliable under clock drift.
  • Reliable under clock adjustments.

Installation

go get -u github.com/multiplay/go-cticker

Examples

Using go-cticker is very much like time.NewTicker with the addition of an accuracy and start time.

The following creates a ticker which ticks on the minute according the hosts wall clock with an accuracy of plus or minus one second.

package main

import (
	"fmt"
	"time"

	"github.com/multiplay/go-cticker"
)

func main() {
	t := cticker.New(time.Minute, time.Second)
	for tick := range t.C {
		// Process tick
		fmt.Println("tick:", tick)
	}
}

Documentation

License

go-cticker is available under the BSD 2-Clause License.