mirror of
https://gitee.com/johng/gf
synced 2026-07-05 05:13:14 +08:00
fix issue in gqueue.Close
This commit is contained in:
@ -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.
|
||||
|
||||
@ -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)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user