goconcurrentcounter

package module
v0.0.0-...-d0e5e85 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2025 License: MIT Imports: 2 Imported by: 2

README

goconcurrentcounter

License: MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Int

type Int interface {

	// GetValue returns the current value of the counter
	GetValue() int
	// Update updates the counter with the given value
	Update(upd int)
	// GetTriggerOnValue returns the trigger function for the given value and name
	GetTriggerOnValue(value int, name string) concurrentIntFunc
	// SetTriggerOnValue sets a trigger function to be executed when the counter reaches the given value
	SetTriggerOnValue(value int, name string, fn concurrentIntFunc)
	// UnsetTriggerOnValue removes the trigger function for the given value and name
	UnsetTriggerOnValue(value int, name string)
	// UnsetTriggersOnValue removes all trigger functions for the given value
	UnsetTriggersOnValue(value int)
	// EnqueueToRunAfterCurrentTriggerFunctions enqueues the given function to be executed after the triggered functions. This function is executed only once.
	EnqueueToRunAfterCurrentTriggerFunctions(fn concurrentIntFunc)
	// contains filtered or unexported methods
}

type IntChan

type IntChan struct {
	// contains filtered or unexported fields
}

concurrent safe Int

func NewIntChan

func NewIntChan(value int) *IntChan

func (*IntChan) EnqueueToRunAfterCurrentTriggerFunctions

func (st *IntChan) EnqueueToRunAfterCurrentTriggerFunctions(fn concurrentIntFunc)

EnqueueToRunAfterCurrentTriggerFunctions enqueues a function to be executed just after the trigger functions

func (*IntChan) GetTriggerOnValue

func (st *IntChan) GetTriggerOnValue(value int, name string) concurrentIntFunc

func (*IntChan) GetValue

func (st *IntChan) GetValue() int

func (*IntChan) SetTriggerOnValue

func (st *IntChan) SetTriggerOnValue(value int, name string, fn concurrentIntFunc)

func (*IntChan) UnsetTriggerOnValue

func (st *IntChan) UnsetTriggerOnValue(value int, name string)

func (*IntChan) UnsetTriggersOnValue

func (st *IntChan) UnsetTriggersOnValue(value int)

func (*IntChan) Update

func (st *IntChan) Update(value int)

type IntMutex

type IntMutex struct {
	// contains filtered or unexported fields
}

IntMutex defines a concurrent-safe int

func NewIntMutex

func NewIntMutex(value int) *IntMutex

NewIntMutex creates and returns a *concurrentInt

func (*IntMutex) EnqueueToRunAfterCurrentTriggerFunctions

func (st *IntMutex) EnqueueToRunAfterCurrentTriggerFunctions(fn concurrentIntFunc)

EnqueueToRunAfterCurrentTriggerFunctions enqueues a function to be executed just after the trigger functions

func (*IntMutex) GetTriggerOnValue

func (st *IntMutex) GetTriggerOnValue(value int, name string) concurrentIntFunc

GetTriggerOnValue returns the trigger function associated to the given value-name. It returns nil if no function is associated to the given values.

func (*IntMutex) GetValue

func (st *IntMutex) GetValue() int

GetValue returns the value

func (*IntMutex) SetTriggerOnValue

func (st *IntMutex) SetTriggerOnValue(value int, name string, fn concurrentIntFunc)

SetTriggerOnValue sets a trigger that would be executed once the given value were reached. Note: do not call UnsetTriggerOnValue() as part of the given function (it would arrive to a deadlock scenario), instead enqueue a function (using EnqueueToRunAfterCurrentTriggerFunctions()) that call it.

func (*IntMutex) UnsetTriggerOnValue

func (st *IntMutex) UnsetTriggerOnValue(value int, name string)

UnsetTriggerOnValue removes the function to be executed on a value

func (*IntMutex) UnsetTriggersOnValue

func (st *IntMutex) UnsetTriggersOnValue(value int)

UnsetTriggersOnValue removes all function to be executed on a given value

func (*IntMutex) Update

func (st *IntMutex) Update(upd int)

Update updates the value. It adds the upd parameter to the value. If the updated value has an associated function, it will be executed.

Jump to

Keyboard shortcuts

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