@@ -29,7 +29,7 @@ pub struct UserWorkerOptions {
29
29
30
30
pub struct MainWorkerOptions {
31
31
pub service_path : PathBuf ,
32
- pub worker_pool_tx : mpsc:: UnboundedSender < WorkerPoolMsg > ,
32
+ pub user_worker_msgs_tx : mpsc:: UnboundedSender < UserWorkerMsgs > ,
33
33
pub no_module_cache : bool ,
34
34
pub import_map_path : Option < String > ,
35
35
}
@@ -39,7 +39,7 @@ impl WorkerContext {
39
39
let service_path = options. service_path ;
40
40
let no_module_cache = options. no_module_cache ;
41
41
let import_map_path = options. import_map_path ;
42
- let worker_pool_tx = options. worker_pool_tx ;
42
+ let user_worker_msgs_tx = options. user_worker_msgs_tx ;
43
43
44
44
// create a unix socket pair
45
45
let ( sender_stream, recv_stream) = UnixStream :: pair ( ) ?;
@@ -49,7 +49,7 @@ impl WorkerContext {
49
49
service_path. clone ( ) ,
50
50
no_module_cache,
51
51
import_map_path,
52
- worker_pool_tx . clone ( ) ,
52
+ user_worker_msgs_tx . clone ( ) ,
53
53
) ?;
54
54
55
55
// start the worker
@@ -145,9 +145,9 @@ pub struct CreateUserWorkerResult {
145
145
}
146
146
147
147
#[ derive( Debug ) ]
148
- pub enum WorkerPoolMsg {
149
- CreateUserWorker ( UserWorkerOptions , oneshot:: Sender < CreateUserWorkerResult > ) ,
150
- SendRequestToWorker ( String , Request < Body > , oneshot:: Sender < Response < Body > > ) ,
148
+ pub enum UserWorkerMsgs {
149
+ Create ( UserWorkerOptions , oneshot:: Sender < CreateUserWorkerResult > ) ,
150
+ SendRequest ( String , Request < Body > , oneshot:: Sender < Response < Body > > ) ,
151
151
}
152
152
153
153
pub struct WorkerPool {
@@ -160,14 +160,15 @@ impl WorkerPool {
160
160
import_map_path : Option < String > ,
161
161
no_module_cache : bool ,
162
162
) -> Result < Self , Error > {
163
- let ( worker_pool_tx, mut worker_pool_rx) = mpsc:: unbounded_channel :: < WorkerPoolMsg > ( ) ;
163
+ let ( user_worker_msgs_tx, mut user_worker_msgs_rx) =
164
+ mpsc:: unbounded_channel :: < UserWorkerMsgs > ( ) ;
164
165
165
166
let main_path = Path :: new ( & main_path) ;
166
167
let main_worker_ctx = WorkerContext :: new_main_worker ( MainWorkerOptions {
167
168
service_path : main_path. to_path_buf ( ) ,
168
169
import_map_path,
169
170
no_module_cache,
170
- worker_pool_tx ,
171
+ user_worker_msgs_tx ,
171
172
} )
172
173
. await ?;
173
174
let main_worker = Arc :: new ( RwLock :: new ( main_worker_ctx) ) ;
@@ -176,9 +177,9 @@ impl WorkerPool {
176
177
let mut user_workers: HashMap < String , Arc < RwLock < WorkerContext > > > = HashMap :: new ( ) ;
177
178
178
179
loop {
179
- match worker_pool_rx . recv ( ) . await {
180
+ match user_worker_msgs_rx . recv ( ) . await {
180
181
None => break ,
181
- Some ( WorkerPoolMsg :: CreateUserWorker ( worker_options, tx) ) => {
182
+ Some ( UserWorkerMsgs :: Create ( worker_options, tx) ) => {
182
183
let key = worker_options. service_path . display ( ) . to_string ( ) ;
183
184
if !user_workers. contains_key ( & key) {
184
185
// TODO: handle errors
@@ -191,7 +192,7 @@ impl WorkerPool {
191
192
192
193
tx. send ( CreateUserWorkerResult { key } ) ;
193
194
}
194
- Some ( WorkerPoolMsg :: SendRequestToWorker ( key, req, tx) ) => {
195
+ Some ( UserWorkerMsgs :: SendRequest ( key, req, tx) ) => {
195
196
// TODO: handle errors
196
197
let worker = user_workers. get ( & key) . unwrap ( ) ;
197
198
let mut worker = worker. write ( ) . await ;
0 commit comments