aboutsummaryrefslogtreecommitdiff
path: root/src/util/background.rs
diff options
context:
space:
mode:
authorTrinity Pointard <trinity.pointard@gmail.com>2021-03-20 20:38:44 +0100
committerAlex Auvolat <alex@adnab.me>2021-04-27 16:37:10 +0200
commitf9bd2d8fb79a8f3dbea54834b39e65438846ea5c (patch)
tree1d8e8bc66f80e29205893dc35187c0980f46f822 /src/util/background.rs
parentbf36f1f16aae763feae7bc7365741d8406f053cb (diff)
downloadgarage-f9bd2d8fb79a8f3dbea54834b39e65438846ea5c.tar.gz
garage-f9bd2d8fb79a8f3dbea54834b39e65438846ea5c.zip
document util crate
Diffstat (limited to 'src/util/background.rs')
-rw-r--r--src/util/background.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/util/background.rs b/src/util/background.rs
index b5eb8bc8..3cbcac2a 100644
--- a/src/util/background.rs
+++ b/src/util/background.rs
@@ -1,3 +1,4 @@
+//! Job runner for futures and async functions
use core::future::Future;
use std::pin::Pin;
use std::sync::Arc;
@@ -12,14 +13,15 @@ use crate::error::Error;
type JobOutput = Result<(), Error>;
type Job = Pin<Box<dyn Future<Output = JobOutput> + Send>>;
+/// Job runner for futures and async functions
pub struct BackgroundRunner {
- pub stop_signal: watch::Receiver<bool>,
-
+ stop_signal: watch::Receiver<bool>,
queue_in: mpsc::UnboundedSender<(Job, bool)>,
worker_in: mpsc::UnboundedSender<tokio::task::JoinHandle<()>>,
}
impl BackgroundRunner {
+ /// Create a new BackgroundRunner
pub fn new(
n_runners: usize,
stop_signal: watch::Receiver<bool>,
@@ -103,7 +105,7 @@ impl BackgroundRunner {
(bgrunner, await_all_done)
}
- // Spawn a task to be run in background
+ /// Spawn a task to be run in background
pub fn spawn<T>(&self, job: T)
where
T: Future<Output = JobOutput> + Send + 'static,
@@ -115,6 +117,8 @@ impl BackgroundRunner {
.unwrap();
}
+ /// Spawn a task to be run in background. It may get discarded before running if spawned while
+ /// the runner is stopping
pub fn spawn_cancellable<T>(&self, job: T)
where
T: Future<Output = JobOutput> + Send + 'static,