missing error handling added

This commit is contained in:
Torsten Harenberg
2025-02-28 14:59:31 +01:00
parent 49058adbfd
commit 4ed3ce9b10
7 changed files with 265 additions and 147 deletions

View File

@@ -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)).