diode/internal/diodes
import "github.com/rs/zerolog/diode/internal/diodes"
Functions
func NewManyToOne(size int, alerter Alerter) *ManyToOne
Source: diode/internal/diodes/many_to_one.go:23
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 NewOneToOne(size int, alerter Alerter) *OneToOne
Source: diode/internal/diodes/one_to_one.go:44
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 NewPoller(d Diode, opts ...PollerConfigOption) *Poller
Source: diode/internal/diodes/poller.go:42
NewPoller returns a new Poller that wraps the given diode.
func NewWaiter(d Diode, opts ...WaiterConfigOption) *Waiter
Source: diode/internal/diodes/waiter.go:30
NewWaiter returns a new Waiter that wraps the given diode.
func WithPollingContext(ctx context.Context) PollerConfigOption
Source: diode/internal/diodes/poller.go:35
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(interval time.Duration) PollerConfigOption
Source: diode/internal/diodes/poller.go:26
WithPollingInterval sets the interval at which the diode is queried for new data. The default is 10ms.
func WithWaiterContext(ctx context.Context) WaiterConfigOption
Source: diode/internal/diodes/waiter.go:23
WithWaiterContext sets the context to cancel any retrieval (Next()). It will not change any results for adding data (Set()). Default is context.Background().
Types
type AlertFunc
Source: diode/internal/diodes/one_to_one.go:19
AlertFunc type is an adapter to allow the use of ordinary functions as Alert handlers.
type AlertFunc func(missed int)func (f AlertFunc) Alert(missed int)
Source: diode/internal/diodes/one_to_one.go:22
Alert calls f(missed)
type Alerter
Source: diode/internal/diodes/one_to_one.go:13
Alerter is used to report how many values were overwritten since the last write.
type Alerter interface {
Alert(missed int)
}Methods
Alert func(missed int)
type Diode
Source: diode/internal/diodes/poller.go:9
Diode is any implementation of a diode.
type Diode interface {
Set(GenericDataType)
TryNext() (GenericDataType, bool)
}Methods
Set func(GenericDataType)TryNext func() (GenericDataType, bool)
type GenericDataType
Source: diode/internal/diodes/one_to_one.go:9
GenericDataType is the data type the diodes operate on.
type GenericDataType unsafe.Pointertype ManyToOne
Source: diode/internal/diodes/many_to_one.go:11
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.
type ManyToOne struct {
// contains filtered or unexported fields
}func (d *ManyToOne) Set(data GenericDataType)
Source: diode/internal/diodes/many_to_one.go:41
Set sets the data in the next slot of the ring buffer.
func (d *ManyToOne) TryNext() (data GenericDataType, ok bool)
Source: diode/internal/diodes/many_to_one.go:70
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
Source: diode/internal/diodes/one_to_one.go:33
OneToOne diode is meant to be used by a single reader and a single writer. It is not thread safe if used otherwise.
type OneToOne struct {
// contains filtered or unexported fields
}func (d *OneToOne) Set(data GenericDataType)
Source: diode/internal/diodes/one_to_one.go:56
Set sets the data in the next slot of the ring buffer.
func (d *OneToOne) TryNext() (data GenericDataType, ok bool)
Source: diode/internal/diodes/one_to_one.go:70
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
Source: diode/internal/diodes/poller.go:15
Poller will poll a diode until a value is available.
type Poller struct {
Diode
// contains filtered or unexported fields
}Fields
Diode
func (p *Poller) Next() GenericDataType
Source: diode/internal/diodes/poller.go:58
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
Source: diode/internal/diodes/poller.go:22
PollerConfigOption can be used to setup the poller.
type PollerConfigOption func(*Poller)type Waiter
Source: diode/internal/diodes/waiter.go:10
Waiter will use a conditional mutex to alert the reader to when data is available.
type Waiter struct {
Diode
// contains filtered or unexported fields
}Fields
Diode
func (w *Waiter) Next() GenericDataType
Source: diode/internal/diodes/waiter.go:63
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 (w *Waiter) Set(data GenericDataType)
Source: diode/internal/diodes/waiter.go:55
Set invokes the wrapped diode's Set with the given data and uses Broadcast to wake up any readers.
type WaiterConfigOption
Source: diode/internal/diodes/waiter.go:18
WaiterConfigOption can be used to setup the waiter.
type WaiterConfigOption func(*Waiter)