Skip to content

Commit

Permalink
feat: remove the dequeue recusion
Browse files Browse the repository at this point in the history
  • Loading branch information
equals215 authored and CorentinB committed Jul 15, 2024
1 parent d81a5ff commit a1f0efd
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions internal/pkg/queue/dequeue.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

// Dequeue removes and returns the next item from the queue
// It blocks until an item is available
func (q *PersistentGroupedQueue) Dequeue() (*Item, error) {
func (q *PersistentGroupedQueue) Dequeue() (item *Item, err error) {
if q.closed {
return nil, ErrQueueClosed
}
Expand Down Expand Up @@ -43,11 +43,10 @@ func (q *PersistentGroupedQueue) Dequeue() (*Item, error) {
q.hostIndex[host] = positions[1:]

// Seek to position and decode item
_, err := q.queueFile.Seek(int64(position), io.SeekStart)
_, err = q.queueFile.Seek(int64(position), io.SeekStart)
if err != nil {
return nil, fmt.Errorf("failed to seek to item position: %w", err)
}
var item Item
err = q.queueDecoder.Decode(&item)
if err != nil {
return nil, fmt.Errorf("failed to decode item: %w", err)
Expand All @@ -64,9 +63,9 @@ func (q *PersistentGroupedQueue) Dequeue() (*Item, error) {
return nil, fmt.Errorf("failed to save metadata: %w", err)
}

return &item, nil
break
}

// If we've checked all hosts and found no items, loop back to wait again
return q.Dequeue()
return
}

0 comments on commit a1f0efd

Please sign in to comment.