cardio

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: CC0-1.0 Imports: 3 Imported by: 0

Documentation

Overview

Package cardio enables Go programs to speed up and slow down based on demand.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Heartbeat

func Heartbeat(ctx context.Context, min, max time.Duration) (<-chan struct{}, func(), func())

Heartbeat is a function that creates a "heartbeat" channel that you can influence to go faster or slower. This is intended to model the behavior of the human heart's ability to slow down and speed up based on physical activity.

The basic usage is something like this:

heartbeat, slower, faster := cardio.Heartbeat(ctx, time.Minute, time.Millisecond)

The min and max arguments control the minimum and maximum heart rate. This returns three things:

- The heartbeat channel that your event loop will poll on - A function to influence the heartbeat to slow down (beacuse there isn't work to do) - A function to influence the heartbeat to speed up (because there is work to do)

Your event loop should look something like this:

for range heartbeat {
    // do something
    if noWork {
        slower()
    } else {
        faster()
    }
}

This will let you have a dynamically adjusting heartbeat for when your sick, twisted desires demand it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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