1
- use std:: { collections:: HashMap , sync:: { Arc , Mutex , MutexGuard , RwLock } } ;
1
+ use std:: {
2
+ collections:: HashMap ,
3
+ sync:: { Arc , Mutex , MutexGuard , RwLock } ,
4
+ } ;
2
5
3
6
use bytes:: Bytes ;
4
- use tokio:: sync:: mpsc:: { Sender , Receiver , channel } ;
7
+ use tokio:: sync:: mpsc:: { channel , Receiver , Sender } ;
5
8
6
- use crate :: { client:: { WorkUpdate , WorkerJob , JobStatus } , conn:: ServerHandle } ;
9
+ use crate :: {
10
+ client:: { JobStatus , WorkUpdate , WorkerJob } ,
11
+ conn:: ServerHandle ,
12
+ } ;
7
13
8
14
pub type JobCreated = ServerHandle ;
9
15
@@ -55,7 +61,10 @@ pub struct ClientData {
55
61
56
62
impl Clone for ClientData {
57
63
fn clone ( & self ) -> Self {
58
- Self { receivers : self . receivers . clone ( ) , senders : self . senders . clone ( ) }
64
+ Self {
65
+ receivers : self . receivers . clone ( ) ,
66
+ senders : self . senders . clone ( ) ,
67
+ }
59
68
}
60
69
}
61
70
@@ -67,7 +76,7 @@ impl ClientReceivers {
67
76
error_rx : Receiver < ( Bytes , Bytes ) > ,
68
77
worker_job_rx : Receiver < WorkerJob > ,
69
78
) -> ClientReceivers {
70
- ClientReceivers {
79
+ ClientReceivers {
71
80
echo_rx : echo_rx,
72
81
job_created_rx : job_created_rx,
73
82
status_res_rx : status_res_rx,
@@ -87,8 +96,20 @@ impl ClientData {
87
96
let ( error_tx, error_rx) = channel ( CLIENT_CHANNEL_BOUND_SIZE ) ;
88
97
let ( worker_job_tx, worker_job_rx) = channel ( CLIENT_CHANNEL_BOUND_SIZE ) ;
89
98
ClientData {
90
- receivers : Arc :: new ( Mutex :: new ( ClientReceivers :: new ( echo_rx, job_created_rx, status_res_rx, error_rx, worker_job_rx) ) ) ,
91
- senders : Arc :: new ( RwLock :: new ( ClientSenders :: new ( echo_tx, job_created_tx, status_res_tx, error_tx, worker_job_tx) ) ) ,
99
+ receivers : Arc :: new ( Mutex :: new ( ClientReceivers :: new (
100
+ echo_rx,
101
+ job_created_rx,
102
+ status_res_rx,
103
+ error_rx,
104
+ worker_job_rx,
105
+ ) ) ) ,
106
+ senders : Arc :: new ( RwLock :: new ( ClientSenders :: new (
107
+ echo_tx,
108
+ job_created_tx,
109
+ status_res_tx,
110
+ error_tx,
111
+ worker_job_tx,
112
+ ) ) ) ,
92
113
}
93
114
}
94
115
@@ -125,7 +146,11 @@ impl ClientData {
125
146
}
126
147
127
148
pub fn set_sender_by_handle ( & mut self , handle : ServerHandle , tx : Sender < WorkUpdate > ) {
128
- self . senders . write ( ) . unwrap ( ) . senders_by_handle . insert ( handle, tx) ;
149
+ self . senders
150
+ . write ( )
151
+ . unwrap ( )
152
+ . senders_by_handle
153
+ . insert ( handle, tx) ;
129
154
}
130
155
131
156
pub fn get_jobs_tx_by_func ( & self , func : & Vec < u8 > ) -> Option < Sender < WorkerJob > > {
@@ -136,6 +161,10 @@ impl ClientData {
136
161
}
137
162
138
163
pub fn set_jobs_tx_by_func ( & mut self , func : Vec < u8 > , tx : Sender < WorkerJob > ) {
139
- self . senders . write ( ) . unwrap ( ) . jobs_tx_by_func . insert ( func, tx) ;
164
+ self . senders
165
+ . write ( )
166
+ . unwrap ( )
167
+ . jobs_tx_by_func
168
+ . insert ( func, tx) ;
140
169
}
141
- }
170
+ }
0 commit comments