From 866482a8e8512857f705c9550e1e09eb57d63d86 Mon Sep 17 00:00:00 2001 From: John Date: Sun, 16 Jun 2019 21:52:41 +0800 Subject: [PATCH] fix issue in gqueue.Close --- g/container/gqueue/gqueue.go | 15 ++++++++++++--- geg/other/test.go | 12 ++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/g/container/gqueue/gqueue.go b/g/container/gqueue/gqueue.go index eb4b2a340..d8ffd2420 100644 --- a/g/container/gqueue/gqueue.go +++ b/g/container/gqueue/gqueue.go @@ -105,9 +105,18 @@ func (q *Queue) Pop() interface{} { // Notice: It would notify all goroutines return immediately, // which are being blocked reading using Pop method. func (q *Queue) Close() { - close(q.C) - close(q.events) - close(q.closed) + if q.C != nil { + close(q.C) + q.C = nil + } + if q.events != nil { + close(q.events) + q.events = nil + } + if q.closed != nil { + close(q.closed) + q.closed = nil + } } // Len returns the length of the queue. diff --git a/geg/other/test.go b/geg/other/test.go index dae805c09..40c961e28 100644 --- a/geg/other/test.go +++ b/geg/other/test.go @@ -7,11 +7,11 @@ import ( func main() { max := 100 - for i := 0; i < 10; i++ { - q := gqueue.New(max) - for i := 1; i < max; i++ { - q.Push(i) - } - gtest.Assert(q.Pop(), 1) + q := gqueue.New(max) + for i := 1; i < max; i++ { + q.Push(i) } + q.Close() + gtest.Assert(q.Len(), 1) + }