mirror of
https://github.com/crazybber/go-pattern-examples.git
synced 2024-11-22 20:06:02 +03:00
21 lines
237 B
Go
21 lines
237 B
Go
package objectpool
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestObjectPool(t *testing.T) {
|
|
|
|
p := newPool(2)
|
|
|
|
select {
|
|
case obj := <-p:
|
|
obj.surgery( /*...*/ )
|
|
|
|
p <- obj
|
|
default:
|
|
// No more objects left — retry later or fail
|
|
return
|
|
}
|
|
}
|