enabler

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2022 License: MIT, MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Enabler

type Enabler interface {
	Enable()
	Disable()
	SetEnableFuncs(enableFunc, disableFunc func())
}

An Enabler represents an object that can be enabled or disabled. It is copied here from the types package to prevent a circular dependency.

Reference: http://

func AddEnabler

func AddEnabler(fnEnable, fnDisable func()) Enabler

AddEnabler implements types.Enabler by using the given Enable and Disa ble methods. If either of these is nil, then the default implementation, a Nop, is used.

This may be used to add Enabler functionality to structures that do not implement the interface natively. For example:

type MyMutex interface {
	sync.Locker
	Enabler
}

type myMutex struct {
	mu *sync.Mutex
	Enabler
}

func (m *MyMutex) fnEnable() {
	m.mu.Lock()
	defer m.mu.Unlock()
	m.fnLock = m.lockFunc
	m.fnUnlock = m.unlockFunc
}

func (m *MyMutex) fnDisable() {
	m.mu.Lock()
	defer m.mu.Unlock()
	m.fnLock = m.noLock
	m.fnUnlock = m.noUnlock
}

var MyMutex myMutex = myMutex{
		mu new(sync.Mutex)
		lockenabler.AddEnabler(fnEnable,fnDisable)
}

Jump to

Keyboard shortcuts

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