enabler

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

package enabler contains a component that can be enabled and disabled dynamically

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Enabler

type Enabler interface {
	Run(ctx context.Context) error
	Enable()
	Disable()
}

An Enabler enables or disables a component dynamically. When the Enabler is enabled, the Handler's RunEnabled will be called. If the Enabler is subsequently disabled the context passed to RunEnabled will be canceled. If the Enabler is subseqently enabled again, RunEnabled will be called again. Handlers should obey the context lifetime and be tolerant of RunEnabled being called multiple times. (not concurrently)

func New

func New(name string, handler Handler, enabled bool) Enabler

New creates a new Enabler.

type Handler

type Handler interface {
	RunEnabled(ctx context.Context) error
}

A Handler is a component with a RunEnabled function.

type HandlerFunc

type HandlerFunc func(ctx context.Context) error

HandlerFunc is a function run by the enabler.

func (HandlerFunc) RunEnabled

func (f HandlerFunc) RunEnabled(ctx context.Context) error

Jump to

Keyboard shortcuts

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