diodes

package
v1.30.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlertFunc

type AlertFunc func(missed int)

AlertFunc type is an adapter to allow the use of ordinary functions as Alert handlers.

func (AlertFunc) Alert

func (f AlertFunc) Alert(missed int)

Alert calls f(missed)

type Alerter

type Alerter interface {
	Alert(missed int)
}

Alerter is used to report how many values were overwritten since the last write.

type Diode

type Diode interface {
	Set(GenericDataType)
	TryNext() (GenericDataType, bool)
}

Diode is any implementation of a diode.

type GenericDataType

type GenericDataType unsafe.Pointer

GenericDataType is the data type the diodes operate on.

type ManyToOne

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

ManyToOne diode is optimal for many writers (go-routines B-n) and a single reader (go-routine A). It is not thread safe for multiple readers.

func NewManyToOne

func NewManyToOne(size int, alerter Alerter) *ManyToOne

NewManyToOne creates a new diode (ring buffer). The ManyToOne diode is optimized for many writers (on go-routines B-n) and a single reader (on go-routine A). The alerter is invoked on the read's go-routine. It is called when it notices that the writer go-routine has passed it and wrote over data. A nil can be used to ignore alerts.

func (*ManyToOne) Set

func (d *ManyToOne) Set(data GenericDataType)

Set sets the data in the next slot of the ring buffer.

func (*ManyToOne) TryNext

func (d *ManyToOne) TryNext() (data GenericDataType, ok bool)

TryNext will attempt to read from the next slot of the ring buffer. If there is no data available, it will return (nil, false).

type OneToOne

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

OneToOne diode is meant to be used by a single reader and a single writer. It is not thread safe if used otherwise.

func NewOneToOne

func NewOneToOne(size int, alerter Alerter) *OneToOne

NewOneToOne creates a new diode is meant to be used by a single reader and a single writer. The alerter is invoked on the read's go-routine. It is called when it notices that the writer go-routine has passed it and wrote over data. A nil can be used to ignore alerts.

func (*OneToOne) Set

func (d *OneToOne) Set(data GenericDataType)

Set sets the data in the next slot of the ring buffer.

func (*OneToOne) TryNext

func (d *OneToOne) TryNext() (data GenericDataType, ok bool)

TryNext will attempt to read from the next slot of the ring buffer. If there is no data available, it will return (nil, false).

type Poller

type Poller struct {
	Diode
	// contains filtered or unexported fields
}

Poller will poll a diode until a value is available.

func NewPoller

func NewPoller(d Diode, opts ...PollerConfigOption) *Poller

NewPoller returns a new Poller that wraps the given diode.

func (*Poller) Next

func (p *Poller) Next() GenericDataType

Next polls the diode until data is available or until the context is done. If the context is done, then nil will be returned.

type PollerConfigOption

type PollerConfigOption func(*Poller)

PollerConfigOption can be used to setup the poller.

func WithPollingContext

func WithPollingContext(ctx context.Context) PollerConfigOption

WithPollingContext sets the context to cancel any retrieval (Next()). It will not change any results for adding data (Set()). Default is context.Background().

func WithPollingInterval

func WithPollingInterval(interval time.Duration) PollerConfigOption

WithPollingInterval sets the interval at which the diode is queried for new data. The default is 10ms.

type Waiter

type Waiter struct {
	Diode
	// contains filtered or unexported fields
}

Waiter will use a conditional mutex to alert the reader to when data is available.

func NewWaiter

func NewWaiter(d Diode, opts ...WaiterConfigOption) *Waiter

NewWaiter returns a new Waiter that wraps the given diode.

func (*Waiter) Next

func (w *Waiter) Next() GenericDataType

Next returns the next data point on the wrapped diode. If there is not any new data, it will Wait for set to be called or the context to be done. If the context is done, then nil will be returned.

func (*Waiter) Set

func (w *Waiter) Set(data GenericDataType)

Set invokes the wrapped diode's Set with the given data and uses Broadcast to wake up any readers.

type WaiterConfigOption

type WaiterConfigOption func(*Waiter)

WaiterConfigOption can be used to setup the waiter.

func WithWaiterContext

func WithWaiterContext(ctx context.Context) WaiterConfigOption

WithWaiterContext sets the context to cancel any retrieval (Next()). It will not change any results for adding data (Set()). Default is context.Background().

Jump to

Keyboard shortcuts

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