fix issue in gqueue in closing channel for limited queue

This commit is contained in:
john
2019-07-22 21:57:17 +08:00
parent 470c696976
commit 86f98f3710
2 changed files with 40 additions and 2 deletions

View File

@ -46,7 +46,7 @@ func New(limit ...int) *Queue {
q := &Queue{
closed: gtype.NewBool(),
}
if len(limit) > 0 {
if len(limit) > 0 && limit[0] > 0 {
q.limit = limit[0]
q.C = make(chan interface{}, limit[0])
} else {
@ -87,7 +87,7 @@ func (q *Queue) startAsyncLoop() {
<-q.events
}
}
// It should be here to close q.C.
// It should be here to close q.C if <q> is unlimited size.
// It's the sender's responsibility to close channel when it should be closed.
close(q.C)
}
@ -119,6 +119,9 @@ func (q *Queue) Close() {
if q.events != nil {
close(q.events)
}
if q.limit > 0 {
close(q.C)
}
for i := 0; i < gDEFAULT_MAX_BATCH_SIZE; i++ {
q.Pop()
}

View File

@ -0,0 +1,35 @@
// Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package gdb_test
import (
"fmt"
"testing"
"github.com/gogf/gf/g/test/gtest"
)
func Test_Types(t *testing.T) {
if _, err := db.Exec(fmt.Sprintf(`
CREATE TABLE types (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
blob blob NOT NULL,
binary binary(8) NOT NULL ,
date varchar(45) NOT NULL ,
decimal decimal(5,2) NOT NULL ',
double double NOT NULL ',
bit bit(2) NOT NULL ',
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
`)); err != nil {
gtest.Error(err)
}
gtest.Case(t, func() {
})
}