pub struct Queue<T> { /* private fields */ }
Expand description
Instance of a queue returning elements of type T
.
Example usage:
use diskqueue::Queue;
let q: Queue<i32> = Queue::new(path).unwrap();
q.enqueue(123).unwrap();
let v = q.dequeue().unwrap();
assert_eq!(v, Some(123));
Implementations§
Source§impl<T> Queue<T>where
T: DeserializeOwned + Serialize,
impl<T> Queue<T>where
T: DeserializeOwned + Serialize,
Sourcepub fn open_or_create(path: PathBuf) -> Result<Self, Error>
pub fn open_or_create(path: PathBuf) -> Result<Self, Error>
Try opening a queue at the given location or create a new queue directory.
Sourcepub fn new(path: PathBuf) -> Result<Self, Error>
pub fn new(path: PathBuf) -> Result<Self, Error>
Create a new queue directory at the given path. The path must not exist.
Sourcepub fn open(path: PathBuf) -> Result<Self, Error>
pub fn open(path: PathBuf) -> Result<Self, Error>
Create a new queue instance for the given path. If the path doesn’t follow the queue directory structure an error is returned.
Sourcepub fn enqueue(&self, payload: T) -> Result<u64, Error>
pub fn enqueue(&self, payload: T) -> Result<u64, Error>
Add the given item to the queue. Returns the unique id of the item.
Sourcepub fn dequeue(&self) -> Result<Option<T>, Error>
pub fn dequeue(&self) -> Result<Option<T>, Error>
Consume a single item from the queue. Returns Ok(None)
if
there was no item that could be consumed, otherwise returns
Ok(Some(T))
. Retries up to 5 times on transient errors
e.g. another process having locked or removed the item
already. If it fails to read five times Ok(None) is returned.
Sourcepub fn dequeue_try_once(&self) -> Result<Option<T>, Error>
pub fn dequeue_try_once(&self) -> Result<Option<T>, Error>
Tries to dequeue a single item from the queue. Compared to
Queue::dequeue this function doesn’t retry and might return
transient errors.
Returns Ok(Some(T))
on success and Ok(None)
when the queue
is empty.