File tree 2 files changed +20
-0
lines changed
2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 6
6
QueueErrorCodeIndexOutOfBounds = "index-out-of-bounds"
7
7
QueueErrorCodeFullCapacity = "full-capacity"
8
8
QueueErrorCodeInternalChannelClosed = "internal-channel-closed"
9
+ QueueErrorCodeValueNotFound = "value-not-found"
9
10
)
10
11
11
12
type QueueError struct {
Original file line number Diff line number Diff line change @@ -259,3 +259,22 @@ func (st *FIFO) IsLocked() bool {
259
259
260
260
return st .isLocked
261
261
}
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