mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in NOTICE, alongside LICENSE. The header lint accepts any copyright line above the SPDX line, so it no longer demands an upstream one. Co-authored-by: Hanzo Dev <[email protected]>
43 lines
893 B
Go
43 lines
893 B
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package queue
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
var pushBlockTime = 5 * time.Second
|
|
|
|
type baseQueue interface {
|
|
PushItem(ctx context.Context, data []byte) error
|
|
PopItem(ctx context.Context) ([]byte, error)
|
|
HasItem(ctx context.Context, data []byte) (bool, error)
|
|
Len(ctx context.Context) (int, error)
|
|
Close() error
|
|
RemoveAll(ctx context.Context) error
|
|
}
|
|
|
|
func popItemByChan(ctx context.Context, popItemFn func(ctx context.Context) ([]byte, error)) (chanItem chan []byte, chanErr chan error) {
|
|
chanItem = make(chan []byte)
|
|
chanErr = make(chan error)
|
|
go func() {
|
|
for {
|
|
it, err := popItemFn(ctx)
|
|
if err != nil {
|
|
close(chanItem)
|
|
chanErr <- err
|
|
return
|
|
}
|
|
if it == nil {
|
|
close(chanItem)
|
|
close(chanErr)
|
|
return
|
|
}
|
|
chanItem <- it
|
|
}
|
|
}()
|
|
return chanItem, chanErr
|
|
}
|