This repository has been archived on 2026-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
ollie-core/agent/fifo.go

30 lines
537 B
Go

package agent
import "sync"
// Fifo is a thread-safe queue for buffered prompts.
type Fifo struct {
mu sync.Mutex
items []string
}
// Push appends a prompt to the queue.
func (f *Fifo) Push(s string) {
f.mu.Lock()
f.items = append(f.items, s)
f.mu.Unlock()
}
// Pop removes and returns the next prompt.
// Returns ("", false) if the queue is empty.
func (f *Fifo) Pop() (string, bool) {
f.mu.Lock()
defer f.mu.Unlock()
if len(f.items) == 0 {
return "", false
}
s := f.items[0]
f.items = f.items[1:]
return s, true
}