capacitor

package
v1.11.9 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2021 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Overview

Package capacitor provides a configurable delay for a series of function calls. A capacitor is discharged when it is time to actually invoke the target function.

Index

Constants

View Source
const DefaultDelay time.Duration = time.Second

DefaultDelay is the default time a capacitor waits to execute the most recently submitted function

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface interface {
	// Submit submits a function for execution.  The function will not be executed immediately.
	// Instead, after a configurable period of time, the most recent function passed to Submit will
	// be executed.  The previous ones are ignored.
	Submit(func())

	// Discharge forcibly discharges this capacitor.  The most recent function passed to Submit is
	// executed, and the internal state is reset so that the next call to Submit will start the
	// process of delaying function calls all over again.
	Discharge()

	// Cancel terminates any waiting function call without executing it.  As with Discharge, the
	// internal state is reset so that Submit calls will delay functions as normal again.
	Cancel()
}

Interface represents a capacitor of function calls which will discharge after a configurable period of time.

func New

func New(o ...Option) Interface

New creates a capacitor with the given options.

type Option

type Option func(*capacitor)

Option represents a configuration option for a capacitor

func WithClock

func WithClock(cl clock.Interface) Option

func WithDelay

func WithDelay(d time.Duration) Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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