From f515db98ba700e5ca8e44e1e975ec96135eca3e7 Mon Sep 17 00:00:00 2001 From: YikesHome <31678324+yikeshome@users.noreply.github.com> Date: Thu, 31 Oct 2019 02:07:57 +0800 Subject: [PATCH] Update object_pool.go --- creational/object_pool.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/creational/object_pool.go b/creational/object_pool.go index 2a73706..6ef65a5 100644 --- a/creational/object_pool.go +++ b/creational/object_pool.go @@ -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 +}