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