Debian Codegraph @

autopaho/queue/queue.go

raw symbols SCIP
1 /*
2 * Copyright (c) 2024 Contributors to the Eclipse Foundation
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v2.0
6 * and Eclipse Distribution License v1.0 which accompany this distribution.
7 *
8 * The Eclipse Public License is available at
9 * https://www.eclipse.org/legal/epl-2.0/
10 * and the Eclipse Distribution License is available at
11 * http://www.eclipse.org/org/documents/edl-v10.php.
12 *
13 * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
14 */
15
16 package queue
17
18 import (
19 "errors"
20 "io"
21 )
22
23 var (
24 ErrEmpty = errors.New("empty queue")
25 )
26
27 // Entry - permits access to a queue entry
28 // Users must call one of Leave, Remove, or Quarantine when done with the entry (and before calling Peek again)
29 // `Reader()` must not be called after calling Leave, Remove, or Quarantine (and any Reader previously requestes should be considered invalid)
30 type Entry interface {
31 Reader() (io.Reader, error) // Provides access to the file contents, subsequent calls may return the same reader
32 Leave() error // Leave the entry in the queue (same entry will be returned on subsequent calls to Peek).
33 Remove() error // Remove this entry from the queue. Returns queue.ErrEmpty if queue is empty after operation
34 Quarantine() error // Flag that this entry has an error (remove from queue, potentially retaining data with error flagged)
35 }
36
37 // Queue provides the functionality needed to manage queued messages
38 type Queue interface {
39 // Wait returns a channel that is closed when there is something in the queue (will return a closed channel if the
40 // queue is empty at the time of the call)
41 Wait() chan struct{}
42
43 // Enqueue add item to the queue.
44 Enqueue(p io.Reader) error
45
46 // Peek retrieves the oldest item from the queue without removing it
47 // Users must call one of Close, Remove, or Quarantine when done with the entry, and before calling Peek again.
48 // Warning: Peek is not safe for concurrent use (it may return the same Entry leading to unpredictable results)
49 Peek() (Entry, error)
50 }