Skip to content

Commit

Permalink
Add NewPoolCustom() (#2)
Browse files Browse the repository at this point in the history
To provide for use case that requires customizations to `sync.Pool`
configuration.
  • Loading branch information
Baliedge authored Oct 31, 2022
1 parent b2fa3c8 commit 195febe
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ func NewPool[T any]() *Pool[T] {
}
}

// NewPoolCustom builds an airmat.Pool that utilizes the user provided
// sync.Pool. The sync.Pool must generate *Mattress[T] values.
func NewPoolCustom[T any](pool *sync.Pool) *Pool[T] {
return &Pool[T]{
sp: pool,
}
}

// Get selects an arbitrary Mattress from the Pool, removes it from the Pool, and returns it to the caller.
// It might return a Slice with some data, but since it should be written by index it's not an issue.
func (p *Pool[T]) Get() *Mattress[T] {
Expand Down

0 comments on commit 195febe

Please sign in to comment.