29 lines
457 B
Go
29 lines
457 B
Go
package plugin
|
|
|
|
import "golang.design/x/lockfree"
|
|
|
|
type Queue[T any] struct {
|
|
queue *lockfree.Queue
|
|
}
|
|
|
|
func NewQueue[T any]() *Queue[T] {
|
|
return &Queue[T]{queue: lockfree.NewQueue()}
|
|
}
|
|
|
|
func (q *Queue[T]) Enqueue(val T) {
|
|
q.queue.Enqueue(val)
|
|
}
|
|
|
|
func (q *Queue[T]) Dequeue() (result T, ok bool) {
|
|
item := q.queue.Dequeue()
|
|
if item == nil {
|
|
ok = false
|
|
return
|
|
}
|
|
return item.(T), true
|
|
}
|
|
|
|
func (q *Queue[T]) Len() uint64 {
|
|
return q.queue.Length()
|
|
}
|