chore: migrate to gitea
Some checks failed
golangci-lint / lint (push) Failing after 21s
Test / test (push) Failing after 2m17s

This commit is contained in:
2026-01-27 01:40:31 +01:00
parent a9bca767a9
commit 1a27ed5274
3163 changed files with 1216358 additions and 1529 deletions

View File

@@ -0,0 +1,53 @@
package queue
import "sync"
// NewEager creates a new eager queue.
func NewEager[T any]() Queue[T] {
return &Eager[T]{}
}
// Eager is a queue that processes items eagerly.
type Eager[T any] struct {
results []T
error error
mu sync.Mutex
}
// Add implements the [Queue] interface.
func (p *Eager[T]) Add(fn func() (T, error)) {
p.mu.Lock()
defer p.mu.Unlock()
// Return early if there's an error
if p.error != nil {
return
}
result, err := fn()
if err != nil {
p.error = err
return
}
p.results = append(p.results, result)
}
// Wait implements the [Queue] interface.
func (p *Eager[T]) Wait() ([]T, error) {
p.mu.Lock()
defer p.mu.Unlock()
if p.error != nil {
return nil, p.error
}
results := p.results
// Reset results for reuse
p.results = nil
return results, nil
}

View File

@@ -0,0 +1,8 @@
// Package queue provides a generic queue implementation.
package queue
// Queue represents a generic queue.
type Queue[T any] interface {
Add(func() (T, error))
Wait() ([]T, error)
}