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
52 lines (47 loc) · 1.54 KB
/
spawner.rs
File metadata and controls
52 lines (47 loc) · 1.54 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
43
44
45
46
47
48
49
50
51
52
//! 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 bittorrent_udp_tracker_core::container::UdpTrackerCoreContainer;
use derive_more::derive::Display;
use derive_more::Constructor;
use tokio::sync::oneshot;
use tokio::task::JoinHandle;
use torrust_server_lib::signals::{Halted, Started};
use super::launcher::Launcher;
use crate::container::UdpTrackerServerContainer;
#[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´.
#[must_use]
pub fn spawn_launcher(
&self,
udp_tracker_core_container: Arc<UdpTrackerCoreContainer>,
udp_tracker_server_container: Arc<UdpTrackerServerContainer>,
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(
udp_tracker_core_container,
udp_tracker_server_container,
spawner.bind_to,
cookie_lifetime,
tx_start,
rx_halt,
)
.await;
spawner
})
}
}