gqueue新增Close方法便于队列优雅退出

This commit is contained in:
John
2018-02-02 14:56:02 +08:00
parent 87568e03f0
commit 421b42fd55
5 changed files with 50 additions and 2 deletions

View File

@ -48,6 +48,11 @@ func (q *StringQueue) Pop() string {
return ""
}
// 关闭队列(通知所有通过Pop阻塞的协程退出)
func (q *StringQueue) Close() {
q.events <- struct{}{}
}
// 获取当前队列大小
func (q *StringQueue) Size() int {
return len(q.events)