Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

batcher: use abstract Queue type for blocks state #12180

Merged
merged 12 commits into from
Oct 2, 2024
13 changes: 4 additions & 9 deletions op-service/queue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ func (q *Queue[T]) Enqueue(t ...T) {
// (if there is one) and returns it. Returns a zero value and false
// if there is no element to dequeue.
func (q *Queue[T]) Dequeue() (T, bool) {
if len(*q) == 0 {
el, ok := q.DequeueN(1)
if !ok {
var zeroValue T
return zeroValue, false
}
t := (*q)[0]
*q = (*q)[1:]
return t, true
return el[0], true
sebastianst marked this conversation as resolved.
Show resolved Hide resolved
}

// DequeueN removes N elements from the front of the queue
Expand Down Expand Up @@ -59,11 +58,7 @@ func (q *Queue[T]) Len() int {
// (if there is one) without removing it. Returns a zero value and
// false if there is no element to peek at.
func (q *Queue[T]) Peek() (T, bool) {
if len(*q) > 0 {
return (*q)[0], true
}
var zeroValue T
return zeroValue, false
return q.PeekN(0)
}

// PeekN returns the element in Nth position in the queue
Expand Down