wake

package
v1.0.41 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package wake reports when the machine resumes from sleep, so subsystems that keep timers or connections can recover from a gap they did not run through.

One detector serves the whole process. It compares how much wall-clock time passed between two of its ticks with how much should have: a process does not run while the machine sleeps, so the first tick after waking lands long after the one before it.

Index

Constants

View Source
const Threshold = time.Minute

Threshold is the smallest wall-clock jump that counts as a wake.

Variables

This section is empty.

Functions

func Detect

func Detect(ctx context.Context, ticks <-chan time.Time, interval time.Duration, now func() time.Time, onWake func(slept time.Duration))

Detect is the detector's loop: it reads the clock once to start and once per tick, and calls onWake when a tick lands at least Threshold later than interval allows. Wall-clock time is compared with its monotonic reading stripped, because on most platforms the monotonic clock stops while the machine sleeps and would hide the gap. A clock set forward by hand looks the same, which costs no more than one extra recovery.

func Subscribe

func Subscribe(ctx context.Context) <-chan time.Duration

Subscribe reports each wake, with roughly how long the machine slept, until ctx ends. Every subscriber shares one detector, which runs while anyone is subscribed. A wake is dropped rather than queued for a subscriber that has not handled the last one yet.

Types

This section is empty.

Jump to

Keyboard shortcuts

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