chore: cleanup codes
This commit is contained in:
@ -2,6 +2,8 @@ package queue
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
// Queue is a simple concurrent safe queue
|
||||
@ -24,7 +26,7 @@ func (q *Queue[T]) Put(items ...T) {
|
||||
// Pop returns the head of items.
|
||||
func (q *Queue[T]) Pop() T {
|
||||
if len(q.items) == 0 {
|
||||
return GetZero[T]()
|
||||
return lo.Empty[T]()
|
||||
}
|
||||
|
||||
q.lock.Lock()
|
||||
@ -37,7 +39,7 @@ func (q *Queue[T]) Pop() T {
|
||||
// Last returns the last of item.
|
||||
func (q *Queue[T]) Last() T {
|
||||
if len(q.items) == 0 {
|
||||
return GetZero[T]()
|
||||
return lo.Empty[T]()
|
||||
}
|
||||
|
||||
q.lock.RLock()
|
||||
@ -69,8 +71,3 @@ func New[T any](hint int64) *Queue[T] {
|
||||
items: make([]T, 0, hint),
|
||||
}
|
||||
}
|
||||
|
||||
func GetZero[T any]() T {
|
||||
var result T
|
||||
return result
|
||||
}
|
||||
|
Reference in New Issue
Block a user