Files
zeekayandHanzo Dev cde37cf581 Go 1.27.1, and the code it can say more simply
Modules declare go 1.27.1 and the build images follow. go fix applied the
modernizers; omitzero is not applied, since it changes what the JSON says.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-16 19:37:50 -07:00

80 lines
1.2 KiB
Go

// Copyright 2019 The go-zeromq Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package zmq4
import (
"container/list"
)
const innerCap = 512
type Queue struct {
rep *list.List
len int
}
func NewQueue() *Queue {
q := &Queue{list.New(), 0}
return q
}
func (q *Queue) Len() int {
return q.len
}
func (q *Queue) Init() {
q.rep.Init()
q.len = 0
}
func (q *Queue) Push(val Msg) {
q.len++
var i []any
elem := q.rep.Back()
if elem != nil {
i = elem.Value.([]any)
}
if i == nil || len(i) == innerCap {
elem = q.rep.PushBack(make([]any, 0, innerCap))
i = elem.Value.([]any)
}
elem.Value = append(i, val)
}
func (q *Queue) Peek() (Msg, bool) {
i := q.front()
if i == nil {
return Msg{}, false
}
return i[0].(Msg), true
}
func (q *Queue) Pop() {
elem := q.rep.Front()
if elem == nil {
panic("attempting to Pop on an empty Queue")
}
q.len--
i := elem.Value.([]any)
i[0] = nil // remove ref to poped element
i = i[1:]
if len(i) == 0 {
q.rep.Remove(elem)
} else {
elem.Value = i
}
}
func (q *Queue) front() []any {
elem := q.rep.Front()
if elem == nil {
return nil
}
return elem.Value.([]any)
}