github.com/haraldrudell/parl@v0.4.176/pslices/queue.go (about) 1 /* 2 © 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) 3 ISC License 4 */ 5 6 package pslices 7 8 import "sync" 9 10 type Queue[T any] struct { 11 lock sync.RWMutex 12 q0, q []T 13 } 14 15 func NewQueue[T any]() (queue *Queue[T]) { 16 return &Queue[T]{} 17 } 18 19 func (q *Queue[T]) Add(value T) { 20 q.lock.Lock() 21 defer q.lock.Unlock() 22 23 q.q = append(q.q, value) 24 } 25 26 func (q *Queue[T]) AddSlice(slice []T) { 27 q.lock.Lock() 28 defer q.lock.Unlock() 29 30 q.q = append(q.q, slice...) 31 } 32 33 func (q *Queue[T]) Remove(value T, ok bool) { 34 q.lock.Lock() 35 defer q.lock.Unlock() 36 37 length := len(q.q) 38 if length > 0 { 39 value = q.q[0] 40 if length > 1 { 41 //copy() 42 _ = length 43 } 44 } 45 _ = value 46 _ = q.q0 47 }