Skip to content

Commit 25e5ea8

Browse files
committed
fix code comment
1 parent b8cb7ea commit 25e5ea8

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

buffer.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var (
2020
ErrFlushTimeout = errors.New("async-buffer: flush timeout")
2121
)
2222

23-
// Flusher hold FlushFunc, Flusher tell Buffer how to flush data.
23+
// Flusher holds FlushFunc, Flusher tell Buffer how to flush data.
2424
type Flusher[T any] interface {
2525
Flush(elements []T) error
2626
}
@@ -29,12 +29,12 @@ type Flusher[T any] interface {
2929
// as a Flusher. FlushFunc(f) is a Flusher that calls f.
3030
type FlushFunc[T any] func(elements []T) error
3131

32-
// Flush calls f(ctx,m)
32+
// Flush calls FlushFunc itself.
3333
func (f FlushFunc[T]) Flush(elements []T) error {
3434
return f(elements)
3535
}
3636

37-
// DefaultErrHandler.
37+
// DefaultErrHandler prints error and the size of elements to stderr.
3838
func DefaultErrHandler[T any](err error, flat []T) {
3939
fmt.Fprintf(
4040
os.Stderr,
@@ -55,7 +55,7 @@ type Option[T any] struct {
5555
// FlushInterval indicates the interval between automatic flushes, set to zero if a negative.
5656
// There is automatic flushing if zero FlushInterval.
5757
FlushInterval time.Duration
58-
// ErrHandler handles errors, print error and elements size to stderr in default.
58+
// ErrHandler handles errors, print error and the size of elements to stderr in default.
5959
ErrHandler func(error, []T)
6060
}
6161

@@ -64,9 +64,9 @@ type Option[T any] struct {
6464
// The Buffer automatically flush data within a cycle
6565
// flushing is also triggered when the data reaches the specified threshold.
6666
//
67-
// If both Threshold and FlushInterval are set to zero, Writing is Flushing.
67+
// If both Threshold and FlushInterval are setted to zero, Writing is Flushing.
6868
//
69-
// You can also flush data manually.
69+
// You can also flush data manually by calling `Flush`.
7070
type Buffer[T any] struct {
7171
ctx context.Context // ctx controls the lifecycle of Buffer
7272
cancel context.CancelFunc // cancel is used to stop Buffer flushing
@@ -75,15 +75,11 @@ type Buffer[T any] struct {
7575
tickerC <-chan time.Time // tickerC flushs datas, when tickerC is nil, Buffer do not timed flushing
7676
tickerStop func() // tickerStop stop the ticker
7777
option Option[T] // options
78-
flusher Flusher[T] // Flusher is the Flusher that flushes outputs the buffer to a permanent destination.
79-
done chan struct{}
78+
flusher Flusher[T] // Flusher is the Flusher that flushes outputs the buffer to a permanent destination
79+
done chan struct{} // done ensures internal `run` function exit
8080
}
8181

8282
// New returns the async buffer based on option
83-
//
84-
// error returned is an error channel that holds errors generated during the flush process.
85-
// You can subscribe to this channel if you want handle flush errors.
86-
// using `se := new(buffer.ErrFlush[T]); errors.As(err, &se)` to get elements that not be flushed.
8783
func New[T any](flusher Flusher[T], option Option[T]) *Buffer[T] {
8884
ctx, cancel := context.WithCancel(context.Background())
8985

@@ -179,7 +175,7 @@ func (b *Buffer[T]) writeDirect(elements []T) (int, error) {
179175
return n, nil
180176
}
181177

182-
// run do flushing in the background and send error to error channel
178+
// run do flushing in the background.
183179
func (b *Buffer[T]) run() {
184180
flat := make([]T, 0, b.option.Threshold)
185181

0 commit comments

Comments
 (0)