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.

base.go 897B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package queue
  4. import (
  5. "context"
  6. "time"
  7. )
  8. var pushBlockTime = 5 * time.Second
  9. type baseQueue interface {
  10. PushItem(ctx context.Context, data []byte) error
  11. PopItem(ctx context.Context) ([]byte, error)
  12. HasItem(ctx context.Context, data []byte) (bool, error)
  13. Len(ctx context.Context) (int, error)
  14. Close() error
  15. RemoveAll(ctx context.Context) error
  16. }
  17. func popItemByChan(ctx context.Context, popItemFn func(ctx context.Context) ([]byte, error)) (chanItem chan []byte, chanErr chan error) {
  18. chanItem = make(chan []byte)
  19. chanErr = make(chan error)
  20. go func() {
  21. for {
  22. it, err := popItemFn(ctx)
  23. if err != nil {
  24. close(chanItem)
  25. chanErr <- err
  26. return
  27. }
  28. if it == nil {
  29. close(chanItem)
  30. close(chanErr)
  31. return
  32. }
  33. chanItem <- it
  34. }
  35. }()
  36. return chanItem, chanErr
  37. }