github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/queue/bytefifo.go (about) 1 // Copyright 2023 The GitBundle Inc. All rights reserved. 2 // Copyright 2017 The Gitea Authors. All rights reserved. 3 // Use of this source code is governed by a MIT-style 4 // license that can be found in the LICENSE file. 5 6 package queue 7 8 import "context" 9 10 // ByteFIFO defines a FIFO that takes a byte array 11 type ByteFIFO interface { 12 // Len returns the length of the fifo 13 Len(ctx context.Context) int64 14 // PushFunc pushes data to the end of the fifo and calls the callback if it is added 15 PushFunc(ctx context.Context, data []byte, fn func() error) error 16 // Pop pops data from the start of the fifo 17 Pop(ctx context.Context) ([]byte, error) 18 // Close this fifo 19 Close() error 20 // PushBack pushes data back to the top of the fifo 21 PushBack(ctx context.Context, data []byte) error 22 } 23 24 // UniqueByteFIFO defines a FIFO that Uniques its contents 25 type UniqueByteFIFO interface { 26 ByteFIFO 27 // Has returns whether the fifo contains this data 28 Has(ctx context.Context, data []byte) (bool, error) 29 } 30 31 var _ ByteFIFO = &DummyByteFIFO{} 32 33 // DummyByteFIFO represents a dummy fifo 34 type DummyByteFIFO struct{} 35 36 // PushFunc returns nil 37 func (*DummyByteFIFO) PushFunc(ctx context.Context, data []byte, fn func() error) error { 38 return nil 39 } 40 41 // Pop returns nil 42 func (*DummyByteFIFO) Pop(ctx context.Context) ([]byte, error) { 43 return []byte{}, nil 44 } 45 46 // Close returns nil 47 func (*DummyByteFIFO) Close() error { 48 return nil 49 } 50 51 // Len is always 0 52 func (*DummyByteFIFO) Len(ctx context.Context) int64 { 53 return 0 54 } 55 56 // PushBack pushes data back to the top of the fifo 57 func (*DummyByteFIFO) PushBack(ctx context.Context, data []byte) error { 58 return nil 59 } 60 61 var _ UniqueByteFIFO = &DummyUniqueByteFIFO{} 62 63 // DummyUniqueByteFIFO represents a dummy unique fifo 64 type DummyUniqueByteFIFO struct { 65 DummyByteFIFO 66 } 67 68 // Has always returns false 69 func (*DummyUniqueByteFIFO) Has(ctx context.Context, data []byte) (bool, error) { 70 return false, nil 71 }