update meter options

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2024-09-04 22:41:05 +03:00
parent 6c68d39081
commit 78f4cd4662
2 changed files with 19 additions and 1 deletions

View File

@ -137,6 +137,13 @@ func WithName(n string) Option {
}
}
// WithMeter sets the meter
func WithMeter(m meter.Meter) Option {
return func(o *Options) {
o.Meter = m
}
}
// WithTimeFunc sets the func to obtain current time
func WithTimeFunc(fn func() time.Time) Option {
return func(o *Options) {

View File

@ -1,6 +1,9 @@
package pool
import "sync"
import (
"bytes"
"sync"
)
type Pool[T any] struct {
p *sync.Pool
@ -23,3 +26,11 @@ func (p Pool[T]) Get() T {
func (p Pool[T]) Put(t T) {
p.p.Put(t)
}
func NewBytePool(size int) Pool[T] {
return NewPool(func() []byte { return make([]byte, size) })
}
func NewBytesPool() Pool[T] {
return NewPool(func() *bytes.Buffer { return bytes.NewBuffer(nil) })
}