File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 66 QueueErrorCodeIndexOutOfBounds = "index-out-of-bounds"
77 QueueErrorCodeFullCapacity = "full-capacity"
88 QueueErrorCodeInternalChannelClosed = "internal-channel-closed"
9+ QueueErrorCodeValueNotFound = "value-not-found"
910)
1011
1112type QueueError struct {
Original file line number Diff line number Diff line change @@ -259,3 +259,22 @@ func (st *FIFO) IsLocked() bool {
259259
260260 return st .isLocked
261261}
262+
263+ func (st * FIFO ) RemoveByValue (value interface {}) error {
264+ if st .isLocked {
265+ return NewQueueError (QueueErrorCodeLockedQueue , "The queue is locked" )
266+ }
267+
268+ st .rwmutex .Lock ()
269+ defer st .rwmutex .Unlock ()
270+
271+ // Find the first occurrence of the value
272+ for i , item := range st .slice {
273+ if item == value {
274+ st .slice = append (st .slice [:i ], st .slice [i + 1 :]... )
275+ return nil
276+ }
277+ }
278+
279+ return NewQueueError (QueueErrorCodeValueNotFound , fmt .Sprintf ("value not found in queue: %v" , value ))
280+ }
You can’t perform that action at this time.
0 commit comments