fedimint_server/consensus/aleph_bft/
spawner.rs1use fedimint_core::task::TaskGroup;
2use fedimint_logging::LOG_CONSENSUS;
3use tracing::warn;
4
5#[derive(Clone)]
6pub struct Spawner {
7 task_group: TaskGroup,
8}
9
10impl Spawner {
11 pub fn new(task_group: TaskGroup) -> Self {
12 Self { task_group }
13 }
14}
15
16impl aleph_bft::SpawnHandle for Spawner {
17 fn spawn(&self, name: &str, task: impl futures::Future<Output = ()> + Send + 'static) {
18 self.task_group.spawn_silent(name, |_| task);
19 }
20
21 fn spawn_essential(
22 &self,
23 name: &str,
24 task: impl futures::Future<Output = ()> + Send + 'static,
25 ) -> aleph_bft::TaskHandle {
26 let (sender, receiver) = futures::channel::oneshot::channel();
27
28 self.task_group.spawn_silent(name, |_| async {
29 task.await;
30
31 if sender.send(()).is_err() {
32 warn!(target: LOG_CONSENSUS, "Unable to send essential spawned task completion. Are we shutting down?");
33 }
34 });
35
36 Box::pin(async { receiver.await.map_err(|_| ()) })
37 }
38}