2020-02-02 16:19:58 -07:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package queue
|
|
|
|
|
2021-05-15 08:22:26 -06:00
|
|
|
import "context"
|
|
|
|
|
2020-02-02 16:19:58 -07:00
|
|
|
// ByteFIFO defines a FIFO that takes a byte array
|
|
|
|
type ByteFIFO interface {
|
|
|
|
// Len returns the length of the fifo
|
2021-05-15 08:22:26 -06:00
|
|
|
Len(ctx context.Context) int64
|
2020-02-02 16:19:58 -07:00
|
|
|
// PushFunc pushes data to the end of the fifo and calls the callback if it is added
|
2021-05-15 08:22:26 -06:00
|
|
|
PushFunc(ctx context.Context, data []byte, fn func() error) error
|
2020-02-02 16:19:58 -07:00
|
|
|
// Pop pops data from the start of the fifo
|
2021-05-15 08:22:26 -06:00
|
|
|
Pop(ctx context.Context) ([]byte, error)
|
2020-02-02 16:19:58 -07:00
|
|
|
// Close this fifo
|
|
|
|
Close() error
|
|
|
|
}
|
|
|
|
|
|
|
|
// UniqueByteFIFO defines a FIFO that Uniques its contents
|
|
|
|
type UniqueByteFIFO interface {
|
|
|
|
ByteFIFO
|
|
|
|
// Has returns whether the fifo contains this data
|
2021-05-15 08:22:26 -06:00
|
|
|
Has(ctx context.Context, data []byte) (bool, error)
|
2020-02-02 16:19:58 -07:00
|
|
|
}
|
|
|
|
|
2021-04-09 01:40:34 -06:00
|
|
|
var _ ByteFIFO = &DummyByteFIFO{}
|
2020-02-02 16:19:58 -07:00
|
|
|
|
|
|
|
// DummyByteFIFO represents a dummy fifo
|
|
|
|
type DummyByteFIFO struct{}
|
|
|
|
|
|
|
|
// PushFunc returns nil
|
2021-05-15 08:22:26 -06:00
|
|
|
func (*DummyByteFIFO) PushFunc(ctx context.Context, data []byte, fn func() error) error {
|
2020-02-02 16:19:58 -07:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pop returns nil
|
2021-05-15 08:22:26 -06:00
|
|
|
func (*DummyByteFIFO) Pop(ctx context.Context) ([]byte, error) {
|
2020-02-02 16:19:58 -07:00
|
|
|
return []byte{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close returns nil
|
|
|
|
func (*DummyByteFIFO) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Len is always 0
|
2021-05-15 08:22:26 -06:00
|
|
|
func (*DummyByteFIFO) Len(ctx context.Context) int64 {
|
2020-02-02 16:19:58 -07:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2021-04-09 01:40:34 -06:00
|
|
|
var _ UniqueByteFIFO = &DummyUniqueByteFIFO{}
|
2020-02-02 16:19:58 -07:00
|
|
|
|
|
|
|
// DummyUniqueByteFIFO represents a dummy unique fifo
|
|
|
|
type DummyUniqueByteFIFO struct {
|
|
|
|
DummyByteFIFO
|
|
|
|
}
|
|
|
|
|
|
|
|
// Has always returns false
|
2021-05-15 08:22:26 -06:00
|
|
|
func (*DummyUniqueByteFIFO) Has(ctx context.Context, data []byte) (bool, error) {
|
2020-02-02 16:19:58 -07:00
|
|
|
return false, nil
|
|
|
|
}
|