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