sshpoke/internal/server/driver/plugin/queue.go

29 lines
457 B
Go
Raw Normal View History

2023-11-17 20:53:52 +03:00
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()
}