2020-02-03 02:19:58 +03: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 17:22:26 +03:00
|
|
|
import "context"
|
|
|
|
|
2020-02-03 02:19:58 +03:00
|
|
|
// ByteFIFO defines a FIFO that takes a byte array
|
|
|
|
type ByteFIFO interface {
|
|
|
|
// Len returns the length of the fifo
|
2021-05-15 17:22:26 +03:00
|
|
|
Len(ctx context.Context) int64
|
2020-02-03 02:19:58 +03:00
|
|
|
// PushFunc pushes data to the end of the fifo and calls the callback if it is added
|
2021-05-15 17:22:26 +03:00
|
|
|
PushFunc(ctx context.Context, data []byte, fn func() error) error
|
2020-02-03 02:19:58 +03:00
|
|
|
// Pop pops data from the start of the fifo
|
2021-05-15 17:22:26 +03:00
|
|
|
Pop(ctx context.Context) ([]byte, error)
|
2020-02-03 02:19:58 +03:00
|
|
|
// Close this fifo
|
|
|
|
Close() error
|
2022-01-23 00:22:14 +03:00
|
|
|
// PushBack pushes data back to the top of the fifo
|
|
|
|
PushBack(ctx context.Context, data []byte) error
|
2020-02-03 02:19:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// UniqueByteFIFO defines a FIFO that Uniques its contents
|
|
|
|
type UniqueByteFIFO interface {
|
|
|
|
ByteFIFO
|
|
|
|
// Has returns whether the fifo contains this data
|
2021-05-15 17:22:26 +03:00
|
|
|
Has(ctx context.Context, data []byte) (bool, error)
|
2020-02-03 02:19:58 +03:00
|
|
|
}
|
|
|
|
|
2021-04-09 10:40:34 +03:00
|
|
|
var _ ByteFIFO = &DummyByteFIFO{}
|
2020-02-03 02:19:58 +03:00
|
|
|
|
|
|
|
// DummyByteFIFO represents a dummy fifo
|
|
|
|
type DummyByteFIFO struct{}
|
|
|
|
|
|
|
|
// PushFunc returns nil
|
2021-05-15 17:22:26 +03:00
|
|
|
func (*DummyByteFIFO) PushFunc(ctx context.Context, data []byte, fn func() error) error {
|
2020-02-03 02:19:58 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pop returns nil
|
2021-05-15 17:22:26 +03:00
|
|
|
func (*DummyByteFIFO) Pop(ctx context.Context) ([]byte, error) {
|
2020-02-03 02:19:58 +03:00
|
|
|
return []byte{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close returns nil
|
|
|
|
func (*DummyByteFIFO) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Len is always 0
|
2021-05-15 17:22:26 +03:00
|
|
|
func (*DummyByteFIFO) Len(ctx context.Context) int64 {
|
2020-02-03 02:19:58 +03:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2022-01-23 00:22:14 +03:00
|
|
|
// PushBack pushes data back to the top of the fifo
|
|
|
|
func (*DummyByteFIFO) PushBack(ctx context.Context, data []byte) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-04-09 10:40:34 +03:00
|
|
|
var _ UniqueByteFIFO = &DummyUniqueByteFIFO{}
|
2020-02-03 02:19:58 +03:00
|
|
|
|
|
|
|
// DummyUniqueByteFIFO represents a dummy unique fifo
|
|
|
|
type DummyUniqueByteFIFO struct {
|
|
|
|
DummyByteFIFO
|
|
|
|
}
|
|
|
|
|
|
|
|
// Has always returns false
|
2021-05-15 17:22:26 +03:00
|
|
|
func (*DummyUniqueByteFIFO) Has(ctx context.Context, data []byte) (bool, error) {
|
2020-02-03 02:19:58 +03:00
|
|
|
return false, nil
|
|
|
|
}
|