Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Skillington committed Feb 7, 2017
1 parent 0af0c9c commit 0b962e6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions pool/object.go
Expand Up @@ -90,7 +90,7 @@ func NewObjectPool(opts ObjectPoolOptions) ObjectPool {

func (p *objectPool) Init(alloc Allocator) {
if !atomic.CompareAndSwapInt32(&p.initialized, 0, 1) {
fn := p.opts.OnPoolAccessError()
fn := p.opts.OnPoolAccessErrorFn()
fn(errPoolAlreadyInitialized)
return
}
Expand All @@ -104,7 +104,7 @@ func (p *objectPool) Init(alloc Allocator) {

func (p *objectPool) Get() interface{} {
if atomic.LoadInt32(&p.initialized) != 1 {
fn := p.opts.OnPoolAccessError()
fn := p.opts.OnPoolAccessErrorFn()
fn(errPoolGetBeforeInitialized)
return p.alloc()
}
Expand All @@ -128,7 +128,7 @@ func (p *objectPool) Get() interface{} {

func (p *objectPool) Put(obj interface{}) {
if atomic.LoadInt32(&p.initialized) != 1 {
fn := p.opts.OnPoolAccessError()
fn := p.opts.OnPoolAccessErrorFn()
fn(errPoolPutBeforeInitialized)
return
}
Expand Down
6 changes: 3 additions & 3 deletions pool/object_test.go
Expand Up @@ -64,7 +64,7 @@ func TestObjectPoolRefillOnLowWaterMark(t *testing.T) {

func TestObjectPoolInitTwiceError(t *testing.T) {
var accessErr error
opts := NewObjectPoolOptions().SetOnPoolAccessError(func(err error) {
opts := NewObjectPoolOptions().SetOnPoolAccessErrorFn(func(err error) {
accessErr = err
})

Expand All @@ -85,7 +85,7 @@ func TestObjectPoolInitTwiceError(t *testing.T) {

func TestObjectPoolGetBeforeInitError(t *testing.T) {
var accessErr error
opts := NewObjectPoolOptions().SetOnPoolAccessError(func(err error) {
opts := NewObjectPoolOptions().SetOnPoolAccessErrorFn(func(err error) {
accessErr = err
})

Expand All @@ -103,7 +103,7 @@ func TestObjectPoolGetBeforeInitError(t *testing.T) {

func TestObjectPoolPutBeforeInitError(t *testing.T) {
var accessErr error
opts := NewObjectPoolOptions().SetOnPoolAccessError(func(err error) {
opts := NewObjectPoolOptions().SetOnPoolAccessErrorFn(func(err error) {
accessErr = err
})

Expand Down
18 changes: 9 additions & 9 deletions pool/options.go
Expand Up @@ -32,16 +32,16 @@ type objectPoolOptions struct {
refillLowWatermark float64
refillHighWatermark float64
instrumentOpts instrument.Options
onPoolAccessError OnPoolAccessError
onPoolAccessErrorFn OnPoolAccessErrorFn
}

// NewObjectPoolOptions creates a new set of object pool options
func NewObjectPoolOptions() ObjectPoolOptions {
return &objectPoolOptions{
size: defaultSize,
refillLowWatermark: defaultRefillLowWatermark,
instrumentOpts: instrument.NewOptions(),
onPoolAccessError: func(err error) { panic(err) },
size: defaultSize,
refillLowWatermark: defaultRefillLowWatermark,
instrumentOpts: instrument.NewOptions(),
onPoolAccessErrorFn: func(err error) { panic(err) },
}
}

Expand Down Expand Up @@ -85,12 +85,12 @@ func (o *objectPoolOptions) InstrumentOptions() instrument.Options {
return o.instrumentOpts
}

func (o *objectPoolOptions) SetOnPoolAccessError(value OnPoolAccessError) ObjectPoolOptions {
func (o *objectPoolOptions) SetOnPoolAccessErrorFn(value OnPoolAccessErrorFn) ObjectPoolOptions {
opts := *o
opts.onPoolAccessError = value
opts.onPoolAccessErrorFn = value
return &opts
}

func (o *objectPoolOptions) OnPoolAccessError() OnPoolAccessError {
return o.onPoolAccessError
func (o *objectPoolOptions) OnPoolAccessErrorFn() OnPoolAccessErrorFn {
return o.onPoolAccessErrorFn
}
12 changes: 6 additions & 6 deletions pool/types.go
Expand Up @@ -56,9 +56,9 @@ type CheckedObjectPool interface {
Get() checked.ReadWriteRef
}

// OnPoolAccessError is a function to call when a pool access error occurs,
// OnPoolAccessErrorFn is a function to call when a pool access error occurs,
// such as get or put before the pool is initialized.
type OnPoolAccessError func(err error)
type OnPoolAccessErrorFn func(err error)

// ObjectPoolOptions provides options for an object pool.
type ObjectPoolOptions interface {
Expand Down Expand Up @@ -90,13 +90,13 @@ type ObjectPoolOptions interface {
// InstrumentOptions returns the instrument options.
InstrumentOptions() instrument.Options

// SetOnPoolAccessError sets the on pool access error callback, by
// SetOnPoolAccessErrorFn sets the on pool access error callback, by
// default this is a panic.
SetOnPoolAccessError(value OnPoolAccessError) ObjectPoolOptions
SetOnPoolAccessErrorFn(value OnPoolAccessErrorFn) ObjectPoolOptions

// OnPoolAccessError returns the on pool access error callback, by
// OnPoolAccessErrorFn returns the on pool access error callback, by
// default this is a panic.
OnPoolAccessError() OnPoolAccessError
OnPoolAccessErrorFn() OnPoolAccessErrorFn
}

// Bucket specifies a pool bucket.
Expand Down

0 comments on commit 0b962e6

Please sign in to comment.