You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bytefifo.go 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package queue
  5. import "context"
  6. // ByteFIFO defines a FIFO that takes a byte array
  7. type ByteFIFO interface {
  8. // Len returns the length of the fifo
  9. Len(ctx context.Context) int64
  10. // PushFunc pushes data to the end of the fifo and calls the callback if it is added
  11. PushFunc(ctx context.Context, data []byte, fn func() error) error
  12. // Pop pops data from the start of the fifo
  13. Pop(ctx context.Context) ([]byte, error)
  14. // Close this fifo
  15. Close() error
  16. }
  17. // UniqueByteFIFO defines a FIFO that Uniques its contents
  18. type UniqueByteFIFO interface {
  19. ByteFIFO
  20. // Has returns whether the fifo contains this data
  21. Has(ctx context.Context, data []byte) (bool, error)
  22. }
  23. var _ ByteFIFO = &DummyByteFIFO{}
  24. // DummyByteFIFO represents a dummy fifo
  25. type DummyByteFIFO struct{}
  26. // PushFunc returns nil
  27. func (*DummyByteFIFO) PushFunc(ctx context.Context, data []byte, fn func() error) error {
  28. return nil
  29. }
  30. // Pop returns nil
  31. func (*DummyByteFIFO) Pop(ctx context.Context) ([]byte, error) {
  32. return []byte{}, nil
  33. }
  34. // Close returns nil
  35. func (*DummyByteFIFO) Close() error {
  36. return nil
  37. }
  38. // Len is always 0
  39. func (*DummyByteFIFO) Len(ctx context.Context) int64 {
  40. return 0
  41. }
  42. var _ UniqueByteFIFO = &DummyUniqueByteFIFO{}
  43. // DummyUniqueByteFIFO represents a dummy unique fifo
  44. type DummyUniqueByteFIFO struct {
  45. DummyByteFIFO
  46. }
  47. // Has always returns false
  48. func (*DummyUniqueByteFIFO) Has(ctx context.Context, data []byte) (bool, error) {
  49. return false, nil
  50. }