hrtimer

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package hrtimer is a one-shot timer that fires with sub-millisecond precision. Go's runtime rounds a timer shorter than 1 ms up to 1 ms when every P is idle (it waits in epoll_wait with a millisecond timeout); Flow arms a timerfd-backed asio timer instead (flow/Net2.actor.cpp:2101-2124). The GRV batch window (RFC-259) needs Flow's precision.

A Timer has one owner goroutine that calls Wait. Reset and Stop may be called from any goroutine, including while Wait is parked. Wait can return for an expiry that a later Reset or Stop superseded, so the owner must recheck its own state after every Wait.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("hrtimer: timer closed")

ErrClosed is returned by Wait, Reset and Stop after Close.

View Source
var ErrUnsupported = errors.New("hrtimer: unsupported platform")

ErrUnsupported is returned by New on platforms without a precise timer; callers fall back to the runtime's timers.

Functions

This section is empty.

Types

type Timer

type Timer struct {
	// contains filtered or unexported fields
}

Timer is a timerfd read through the netpoller: Wait parks the goroutine without holding a thread or P, and a ready timerfd wakes epoll_wait whatever the runtime's own timeout.

func New

func New() (*Timer, error)

New creates a disarmed timer.

func (*Timer) Close

func (t *Timer) Close() error

Close releases the timerfd and wakes a parked Wait.

func (*Timer) Reset

func (t *Timer) Reset(d time.Duration) error

Reset arms the timer to expire d from now, replacing any pending expiry. d <= 0 arms the shortest delay, since a zero it_value would disarm it. On error the timer is unchanged.

func (*Timer) Stop

func (t *Timer) Stop() error

Stop disarms the timer. A Wait already parked stays parked.

func (*Timer) Wait

func (t *Timer) Wait() error

Wait blocks until an expiry is consumed. It returns ErrClosed once Close has been called, including for a Wait parked at the time.

Jump to

Keyboard shortcuts

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