mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-22 04:36:02 +03:00
Update object_pool.go
This commit is contained in:
parent
2584747936
commit
f515db98ba
@ -11,3 +11,17 @@ func New(total int) *Pool {
|
||||
|
||||
return &p
|
||||
}
|
||||
|
||||
|
||||
|
||||
p := New(2)
|
||||
|
||||
select {
|
||||
case obj := <-p:
|
||||
obj.Do( /*...*/ )
|
||||
|
||||
p <- obj
|
||||
default:
|
||||
// No more objects left — retry later or fail
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user