From 668ab73b629dd830053c4eeaded6749d94d95e5b Mon Sep 17 00:00:00 2001 From: Pramono Date: Wed, 9 Oct 2019 23:19:52 +0700 Subject: [PATCH] creational/singleton: avoid another object creation --- creational/singleton.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/creational/singleton.md b/creational/singleton.md index 632cdf8..5c3407b 100644 --- a/creational/singleton.md +++ b/creational/singleton.md @@ -16,9 +16,11 @@ var ( ) func New() singleton { - once.Do(func() { - instance = make(singleton) - }) + if singleton == nil { + once.Do(func() { + instance = make(singleton) + }) + } return instance }