@@ -96,7 +96,7 @@ pub struct UdpServer<S> {
96
96
/// A stopped UDP server state.
97
97
98
98
pub struct Stopped {
99
- launcher : Launcher ,
99
+ launcher : Spawner ,
100
100
}
101
101
102
102
/// A running UDP server state.
@@ -105,13 +105,13 @@ pub struct Running {
105
105
/// The address where the server is bound.
106
106
pub binding : SocketAddr ,
107
107
pub halt_task : tokio:: sync:: oneshot:: Sender < Halted > ,
108
- pub task : JoinHandle < Launcher > ,
108
+ pub task : JoinHandle < Spawner > ,
109
109
}
110
110
111
111
impl UdpServer < Stopped > {
112
112
/// Creates a new `UdpServer` instance in `stopped`state.
113
113
#[ must_use]
114
- pub fn new ( launcher : Launcher ) -> Self {
114
+ pub fn new ( launcher : Spawner ) -> Self {
115
115
Self {
116
116
state : Stopped { launcher } ,
117
117
}
@@ -140,7 +140,7 @@ impl UdpServer<Stopped> {
140
140
let binding = rx_start. await . expect ( "it should be able to start the service" ) . address ;
141
141
let local_addr = format ! ( "udp://{binding}" ) ;
142
142
143
- form. send ( ServiceRegistration :: new ( binding, Udp :: check) )
143
+ form. send ( ServiceRegistration :: new ( binding, Launcher :: check) )
144
144
. expect ( "it should be able to send service registration" ) ;
145
145
146
146
let running_udp_server: UdpServer < Running > = UdpServer {
@@ -186,12 +186,12 @@ impl UdpServer<Running> {
186
186
}
187
187
188
188
#[ derive( Constructor , Copy , Clone , Debug ) ]
189
- pub struct Launcher {
189
+ pub struct Spawner {
190
190
bind_to : SocketAddr ,
191
191
}
192
192
193
- impl Launcher {
194
- /// It starts the UDP server instance.
193
+ impl Spawner {
194
+ /// It spawns a new tasks to run the UDP server instance.
195
195
///
196
196
/// # Panics
197
197
///
@@ -201,10 +201,10 @@ impl Launcher {
201
201
tracker : Arc < Tracker > ,
202
202
tx_start : oneshot:: Sender < Started > ,
203
203
rx_halt : oneshot:: Receiver < Halted > ,
204
- ) -> JoinHandle < Launcher > {
205
- let launcher = Launcher :: new ( self . bind_to ) ;
204
+ ) -> JoinHandle < Spawner > {
205
+ let launcher = Spawner :: new ( self . bind_to ) ;
206
206
tokio:: spawn ( async move {
207
- Udp :: run_with_graceful_shutdown ( tracker, launcher. bind_to , tx_start, rx_halt) . await ;
207
+ Launcher :: run_with_graceful_shutdown ( tracker, launcher. bind_to , tx_start, rx_halt) . await ;
208
208
launcher
209
209
} )
210
210
}
@@ -388,9 +388,9 @@ impl Stream for Receiver {
388
388
389
389
/// A UDP server instance launcher.
390
390
#[ derive( Constructor ) ]
391
- pub struct Udp ;
391
+ pub struct Launcher ;
392
392
393
- impl Udp {
393
+ impl Launcher {
394
394
/// It starts the UDP server instance with graceful shutdown.
395
395
///
396
396
/// # Panics
@@ -502,7 +502,8 @@ impl Udp {
502
502
*/
503
503
504
504
let abort_handle =
505
- tokio:: task:: spawn ( Udp :: process_request ( req, tracker. clone ( ) , receiver. bound_socket . clone ( ) ) ) . abort_handle ( ) ;
505
+ tokio:: task:: spawn ( Launcher :: process_request ( req, tracker. clone ( ) , receiver. bound_socket . clone ( ) ) )
506
+ . abort_handle ( ) ;
506
507
507
508
if abort_handle. is_finished ( ) {
508
509
continue ;
@@ -589,7 +590,7 @@ mod tests {
589
590
590
591
use crate :: bootstrap:: app:: initialize_with_configuration;
591
592
use crate :: servers:: registar:: Registar ;
592
- use crate :: servers:: udp:: server:: { Launcher , UdpServer } ;
593
+ use crate :: servers:: udp:: server:: { Spawner , UdpServer } ;
593
594
594
595
#[ tokio:: test]
595
596
async fn it_should_be_able_to_start_and_stop ( ) {
@@ -600,7 +601,7 @@ mod tests {
600
601
let bind_to = config. bind_address ;
601
602
let register = & Registar :: default ( ) ;
602
603
603
- let stopped = UdpServer :: new ( Launcher :: new ( bind_to) ) ;
604
+ let stopped = UdpServer :: new ( Spawner :: new ( bind_to) ) ;
604
605
605
606
let started = stopped
606
607
. start ( tracker, register. give_form ( ) )
@@ -622,7 +623,7 @@ mod tests {
622
623
let bind_to = config. bind_address ;
623
624
let register = & Registar :: default ( ) ;
624
625
625
- let stopped = UdpServer :: new ( Launcher :: new ( bind_to) ) ;
626
+ let stopped = UdpServer :: new ( Spawner :: new ( bind_to) ) ;
626
627
627
628
let started = stopped
628
629
. start ( tracker, register. give_form ( ) )
0 commit comments