forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspawner.rs
More file actions
42 lines (37 loc) · 1.19 KB
/
spawner.rs
File metadata and controls
42 lines (37 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//! A thin wrapper for tokio spawn to launch the UDP server launcher as a new task.
use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Duration;
use derive_more::derive::Display;
use derive_more::Constructor;
use tokio::sync::oneshot;
use tokio::task::JoinHandle;
use super::launcher::Launcher;
use crate::bootstrap::jobs::Started;
use crate::core::Tracker;
use crate::servers::signals::Halted;
#[derive(Constructor, Copy, Clone, Debug, Display)]
#[display("(with socket): {bind_to}")]
pub struct Spawner {
pub bind_to: SocketAddr,
}
impl Spawner {
/// It spawns a new task to run the UDP server instance.
///
/// # Panics
///
/// It would panic if unable to resolve the `local_addr` from the supplied ´socket´.
pub fn spawn_launcher(
&self,
tracker: Arc<Tracker>,
cookie_lifetime: Duration,
tx_start: oneshot::Sender<Started>,
rx_halt: oneshot::Receiver<Halted>,
) -> JoinHandle<Spawner> {
let spawner = Self::new(self.bind_to);
tokio::spawn(async move {
Launcher::run_with_graceful_shutdown(tracker, spawner.bind_to, cookie_lifetime, tx_start, rx_halt).await;
spawner
})
}
}