about summary refs log tree commit diff
path: root/util/src/queue.rs
diff options
context:
space:
mode:
Diffstat (limited to 'util/src/queue.rs')
-rw-r--r--util/src/queue.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/util/src/queue.rs b/util/src/queue.rs
index c880597..edbec86 100644
--- a/util/src/queue.rs
+++ b/util/src/queue.rs
@@ -1,8 +1,11 @@
+use std::future::Future;
 use futures_util::Stream;
 use std::pin::Pin;
 use uuid::Uuid;
 
-#[async_trait::async_trait]
+/// A stream of jobs from the job queue.
+pub type JobStream<J, E> = Pin<Box<dyn Stream<Item = Result<J, E>> + Send>>;
+
 /// A job queue that can store and return jobs.
 pub trait JobQueue<T: JobItem>: Send + Sync + Sized + Clone + 'static {
     /// A type of job object that will be returned by the queue.
@@ -17,13 +20,14 @@ pub trait JobQueue<T: JobItem>: Send + Sync + Sized + Clone + 'static {
     ///
     /// Returns an error if a job queue failed in some way. Having no
     /// items is not a failure, in which case `Ok(None)` is returned.
-    async fn get_one(&self) -> Result<Option<Self::Job>, Self::Error>;
+    #[must_use = "Undone jobs get put back into the queue."]
+    fn get_one(&self) -> impl Future<Output = Result<Option<Self::Job>, Self::Error>> + Send;
     /// Put an item into a job queue, returning its UUID.
-    async fn put(&self, item: &T) -> Result<Uuid, Self::Error>;
+    fn put(&self, item: &T) -> impl Future<Output = Result<Uuid, Self::Error>> + Send;
 
     /*
     /// Check the amount of pending and stuck items in the job queue.
-    async fn len(&self) -> Result<(usize, usize), Self::Error>;
+    fn len(&self) -> impl Future<Output = Result<(usize, usize), Self::Error>> + Send;
     /// Returns whether the job queue has some pending items.
     async fn is_empty(&self) -> Result<bool, Self::Error> {
         Ok(self.len().await?.0 == 0)
@@ -40,10 +44,9 @@ pub trait JobQueue<T: JobItem>: Send + Sync + Sized + Clone + 'static {
     ///
     /// Note that one item may be returned several times if it is not
     /// marked as done.
-    async fn into_stream(self) -> Result<Pin<Box<dyn Stream<Item = Result<Self::Job, Self::Error>> + Send>>, Self::Error>;
+    fn into_stream(self) -> impl Future<Output = Result<JobStream<Self::Job, Self::Error>, Self::Error>> + Send;
 }
 
-#[async_trait::async_trait]
 /// A job description yielded from a job queue.
 ///
 /// # Implementors
@@ -58,7 +61,7 @@ pub trait Job<T: JobItem, Q: JobQueue<T>>: Send + Sync + Sized {
     /// Get the object describing the task itself.
     fn job(&self) -> &T;
     /// Mark the job as done and remove it from the job queue.
-    async fn done(self) -> Result<(), Q::Error>;
+    fn done(self) -> impl Future<Output = Result<(), Q::Error>> + Send;
 }
 
 /// An object describing the job itself, returned as part of a