aboutsummaryrefslogtreecommitdiff
path: root/src/util/background.rs
diff options
context:
space:
mode:
authorAlex <alex@adnab.me>2021-04-08 15:01:13 +0200
committerAlex <alex@adnab.me>2021-04-08 15:01:13 +0200
commitc35c472dc9b04ed49e28a78bc9fa96baa7282502 (patch)
treecb7390fabc55b047b2d75a0af3f3db9ab9d247bc /src/util/background.rs
parentc3bd672d58d32c8fc3b3225bfc2bfb5330ec726e (diff)
parent718ae005486baeed358d56cc7cd319fedd1e76eb (diff)
downloadgarage-c35c472dc9b04ed49e28a78bc9fa96baa7282502.tar.gz
garage-c35c472dc9b04ed49e28a78bc9fa96baa7282502.zip
Merge pull request 'add doc comments' (#53) from trinity-1686a/garage:doc-comments into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/53
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..bfdaaf1e 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,