code.gitea.io/gitea@v1.19.3/modules/queue/unique_queue.go (about) 1 // Copyright 2020 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package queue 5 6 import ( 7 "fmt" 8 ) 9 10 // UniqueQueue defines a queue which guarantees only one instance of same 11 // data is in the queue. Instances with same identity will be 12 // discarded if there is already one in the line. 13 // 14 // This queue is particularly useful for preventing duplicated task 15 // of same purpose - please note that this does not guarantee that a particular 16 // task cannot be processed twice or more at the same time. Uniqueness is 17 // only guaranteed whilst the task is waiting in the queue. 18 // 19 // Users of this queue should be careful to push only the identifier of the 20 // data 21 type UniqueQueue interface { 22 Queue 23 PushFunc(Data, func() error) error 24 Has(Data) (bool, error) 25 } 26 27 // ErrAlreadyInQueue is returned when trying to push data to the queue that is already in the queue 28 var ErrAlreadyInQueue = fmt.Errorf("already in queue")