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