fix issue in gqueue.Close

This commit is contained in:
John
2019-06-16 21:52:41 +08:00
parent c342310389
commit 866482a8e8
2 changed files with 18 additions and 9 deletions

View File

@ -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.

View File

@ -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)
}