Documentation
¶
Index ¶
Constants ¶
const DefaultDataBackupSize = 128
DefaultDataBackupSize is the default size of buffer data backup
Variables ¶
var ( // ErrClosed represents a closed buffer ErrClosed = errors.New("async-buffer: buffer is closed") )
Functions ¶
func NewErrFlush ¶
NewErrFlush return ErrFlush, error is flush error, elements is elements that not be handled.
Types ¶
type Buffer ¶
type Buffer[T any] struct { // contains filtered or unexported fields }
Buffer represents an async buffer
The Buffer automatically flush data within a cycle flushing is also triggered when the data reaches the specified threshold
You can also flush data manually
func New ¶
func New[T any](threshold uint32, flushInterval time.Duration, flusher Flusher[T]) (*Buffer[T], <-chan error)
New return the async buffer
threshold indicates that the buffer is large enough to trigger flushing, if threshold is zero, do not judge threshold. flushInterval indicates the interval between automatic flushes, flusher is the Flusher that flushes outputs the buffer to a permanent destination.
error returned is an error channel that holds errors generated during the flush process. You can subscribe to this channel if you want handle flush errors. using `errors.As(err, ErrFlush)` to get elements that not be flushed.
type ErrFlush ¶
type ErrFlush[T any] struct { Backup []T // contains filtered or unexported fields }
ErrFlush is returned form `Write` when automatic flushing error,