Skip to content

Commit

Permalink
Hack queue to return the last element when empty, and then stop
Browse files Browse the repository at this point in the history
  • Loading branch information
gberche-orange committed Nov 7, 2024
1 parent d4e3a08 commit 41619fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,8 @@ func httpHandler(res http.ResponseWriter, req *http.Request) {
}

fmt.Fprintf(res, metric.Format())
if liveMetrics.isLastMetric() {
break
}
}
}
4 changes: 4 additions & 0 deletions cmd/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ func (q *Queue[T]) Pop() (*T, bool) {

return &val, true
}

func (q *Queue[T]) isLastMetric() bool {
return q.Size == 1
}

0 comments on commit 41619fc

Please sign in to comment.