Skip to content

Commit b271b11

Browse files
committed
Now that wait() does not use the eventloop/signalling chans, just bundle them up in a tuple
1 parent 3d42fd2 commit b271b11

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

http/src/lib.rs

+13-22
Original file line numberDiff line numberDiff line change
@@ -437,19 +437,17 @@ impl<M: jsonrpc::Metadata, S: jsonrpc::Middleware<M>> ServerBuilder<M, S> {
437437
.collect::<io::Result<(Vec<_>)>>()?;
438438
handles.push((eloop, close, done_rx));
439439

440-
let (executors, closers, done_rxs) = handles
440+
let (executors, done_rxs) = handles
441441
.into_iter()
442-
.fold((vec![], vec![], vec![]), |mut acc, (eloop, closer, done_rx)| {
443-
acc.0.push(eloop);
444-
acc.1.push(closer);
445-
acc.2.push(done_rx);
442+
.fold((vec![], vec![]), |mut acc, (eloop, closer, done_rx)| {
443+
acc.0.push((eloop, closer));
444+
acc.1.push(done_rx);
446445
acc
447446
});
448447

449448
Ok(Server {
450449
address: local_addr?,
451450
executors: Arc::new(Mutex::new(Some(executors))),
452-
close: Arc::new(Mutex::new(Some(closers))),
453451
done: Some(done_rxs),
454452
})
455453
}
@@ -581,30 +579,26 @@ fn configure_port(_reuse: bool, _tcp: &net2::TcpBuilder) -> io::Result<()> {
581579

582580
/// Handle used to close the server. Can be cloned and passed around to different threads and be used
583581
/// to close a server that is `wait()`ing.
582+
584583
#[derive(Clone)]
585-
pub struct CloseHandle {
586-
executors: Arc<Mutex<Option<Vec<Executor>>>>,
587-
closers: Arc<Mutex<Option<Vec<oneshot::Sender<()>>>>>,
588-
}
584+
pub struct CloseHandle(Arc<Mutex<Option<Vec<(Executor, oneshot::Sender<()>)>>>>);
589585

590586
impl CloseHandle {
591587
/// Shutdown a running server
592588
pub fn close(self) {
593-
if let Some(executors) = self.executors.lock().take() {
594-
for executor in executors { executor.close() }
595-
}
596-
597-
if let Some(closers) = self.closers.lock().take() {
598-
for closer in closers { let _ = closer.send(()); }
589+
if let Some(executors) = self.0.lock().take() {
590+
for (executor, closer) in executors {
591+
executor.close();
592+
let _ = closer.send(());
593+
}
599594
}
600595
}
601596
}
602597

603598
/// jsonrpc http server instance
604599
pub struct Server {
605600
address: SocketAddr,
606-
executors: Arc<Mutex<Option<Vec<Executor>>>>,
607-
close: Arc<Mutex<Option<Vec<oneshot::Sender<()>>>>>,
601+
executors: Arc<Mutex<Option<Vec<(Executor, oneshot::Sender<()>)>>>>,
608602
done: Option<Vec<oneshot::Receiver<()>>>,
609603
}
610604

@@ -631,10 +625,7 @@ impl Server {
631625
/// Get a handle that allows us to close the server from a different thread and/or while the
632626
/// server is `wait()`ing.
633627
pub fn close_handle(&self) -> CloseHandle {
634-
CloseHandle {
635-
executors: self.executors.clone(),
636-
closers: self.close.clone(),
637-
}
628+
CloseHandle(self.executors.clone())
638629
}
639630
}
640631

0 commit comments

Comments
 (0)