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.

unique_queue.go 1010B

1234567891011121314151617181920212223242526272829
  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 (
  6. "fmt"
  7. )
  8. // UniqueQueue defines a queue which guarantees only one instance of same
  9. // data is in the queue. Instances with same identity will be
  10. // discarded if there is already one in the line.
  11. //
  12. // This queue is particularly useful for preventing duplicated task
  13. // of same purpose - please note that this does not guarantee that a particular
  14. // task cannot be processed twice or more at the same time. Uniqueness is
  15. // only guaranteed whilst the task is waiting in the queue.
  16. //
  17. // Users of this queue should be careful to push only the identifier of the
  18. // data
  19. type UniqueQueue interface {
  20. Queue
  21. PushFunc(Data, func() error) error
  22. Has(Data) (bool, error)
  23. }
  24. // ErrAlreadyInQueue is returned when trying to push data to the queue that is already in the queue
  25. var ErrAlreadyInQueue = fmt.Errorf("already in queue")