missing error handling added
This commit is contained in:
7
fifo.go
7
fifo.go
@@ -116,7 +116,7 @@ func (f *ByteFIFO) Peek(n int) ([]byte, error) {
|
||||
return f.buffer[:n], nil
|
||||
}
|
||||
|
||||
// Size returns the current number of bytes in the buffer.
|
||||
// GetLen returns the current number of bytes in the buffer.
|
||||
func (f *ByteFIFO) GetLen() int {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
@@ -137,7 +137,7 @@ type StringFIFO struct {
|
||||
cond *sync.Cond // Condition variable for signaling
|
||||
}
|
||||
|
||||
// NewByteFIFO creates a new ByteFIFO with the given capacity.
|
||||
// NewStringFIFO creates a new StringFIFO.
|
||||
func NewStringFIFO() *StringFIFO {
|
||||
fifo := &StringFIFO{
|
||||
buffer: make([]string, 0),
|
||||
@@ -147,13 +147,12 @@ func NewStringFIFO() *StringFIFO {
|
||||
}
|
||||
|
||||
// Enqueue adds a string to the end of the buffer. Returns an error if the buffer is full.
|
||||
func (f *StringFIFO) Enqueue(data string) error {
|
||||
func (f *StringFIFO) Enqueue(data string) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
f.buffer = append(f.buffer, data)
|
||||
f.cond.Signal() // Notify waiting goroutines that data is available
|
||||
return nil
|
||||
}
|
||||
|
||||
// Dequeue removes and returns the first `n` bytes from the buffer (or what's left if n>len(f.buffer)).
|
||||
|
Reference in New Issue
Block a user