@@ -12,6 +12,7 @@ use std::sync::{
1212use std::{collections::HashMap, process::Stdio};
1313use tokio::{
1414 io::{AsyncBufRead, AsyncWrite, BufReader, BufWriter},
15+ join,
1516 net::TcpStream,
1617 process::{Child, Command},
1718 sync::{
@@ -449,7 +450,12 @@ impl Client {
449450 self.request_counter.fetch_add(1, Ordering::Relaxed)
450451 }
451452
452− async fn request(&self, command: String, arguments: Option<Value>) -> Result<Response> {
453+ async fn request(
454+ &self,
455+ command: String,
456+ arguments: Option<Value>,
457+ response: bool,
458+ ) -> Result<Option<Response>> {
453459 let (callback_rx, mut callback_tx) = channel(1);
454460
455461 let req = Request {
@@ -464,10 +470,11 @@ impl Client {
464470 .send(req)
465471 .expect("Failed to send request to debugger");
466472
467− callback_tx
468− .recv()
469− .await
470− .expect("Failed to receive response")
473+ if response {
474+ Ok(Some(callback_tx.recv().await.unwrap()?))
475+ } else {
476+ Ok(None)
477+ }
471478 }
472479
473480 pub fn capabilities(&self) -> &DebuggerCapabilities {
@@ -494,25 +501,25 @@ impl Client {
494501 };
495502
496503 let response = self
497− .request("initialize".to_owned(), to_value(args).ok())
498− .await?;
504+ .request("initialize".to_owned(), to_value(args).ok(), true)
505+ .await?
506+ .unwrap();
499507 self.capabilities = from_value(response.body.unwrap()).ok();
500508
501509 Ok(())
502510 }
503511
504512 pub async fn disconnect(&mut self) -> Result<()> {
505− self.request("disconnect".to_owned(), None).await?;
513+ self.request("disconnect".to_owned(), None, true).await?;
506514 Ok(())
507515 }
508516
509517 pub async fn launch(&mut self, args: impl Serialize) -> Result<()> {
510518 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
511519
512− self.request("launch".to_owned(), to_value(args).ok())
513− .await?;
514−
515− initialized.recv().await;
520+ let res = self.request("launch".to_owned(), to_value(args).ok(), false);
521+ let ev = initialized.recv();
522+ join!(res, ev).0?;
516523
517524 Ok(())
518525 }
@@ -520,10 +527,9 @@ impl Client {
520527 pub async fn attach(&mut self, args: impl Serialize) -> Result<()> {
521528 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
522529
523− self.request("attach".to_owned(), to_value(args).ok())
524− .await?;
525−
526− initialized.recv().await;
530+ let res = self.request("attach".to_owned(), to_value(args).ok(), false);
531+ let ev = initialized.recv();
532+ join!(res, ev).0?;
527533
528534 Ok(())
529535 }
@@ -549,15 +555,17 @@ impl Client {
549555 };
550556
551557 let response = self
552− .request("setBreakpoints".to_owned(), to_value(args).ok())
553− .await?;
558+ .request("setBreakpoints".to_owned(), to_value(args).ok(), true)
559+ .await?
560+ .unwrap();
554561 let body: Option<SetBreakpointsResponseBody> = from_value(response.body.unwrap()).ok();
555562
556563 Ok(body.map(|b| b.breakpoints).unwrap())
557564 }
558565
559566 pub async fn configuration_done(&mut self) -> Result<()> {
560− self.request("configurationDone".to_owned(), None).await?;
567+ self.request("configurationDone".to_owned(), None, true)
568+ .await?;
561569 Ok(())
562570 }
563571
@@ -565,8 +573,9 @@ impl Client {
565573 let args = ContinueArguments { thread_id };
566574
567575 let response = self
568− .request("continue".to_owned(), to_value(args).ok())
569− .await?;
576+ .request("continue".to_owned(), to_value(args).ok(), true)
577+ .await?
578+ .unwrap();
570579
571580 let body: Option<ContinueResponseBody> = from_value(response.body.unwrap()).ok();
572581
@@ -585,8 +594,8 @@ impl Client {
585594 };
586595
587596 let response = self
588− .request("stackTrace".to_owned(), to_value(args).ok())
589− .await?;
597+ .request("stackTrace".to_owned(), to_value(args).ok(), true)
598+ .await?.unwrap();
590599
591600 let body: StackTraceResponseBody = from_value(response.body.unwrap()).unwrap();
592601
@@ -594,7 +603,7 @@ impl Client {
594603 }
595604
596605 pub async fn threads(&mut self) -> Result<Vec<Thread>> {
597− let response = self.request("threads".to_owned(), None).await?;
606+ let response = self.request("threads".to_owned(), None, true).await?.unwrap();
598607
599608 let body: ThreadsResponseBody = from_value(response.body.unwrap()).unwrap();
600609
@@ -605,8 +614,8 @@ impl Client {
605614 let args = ScopesArguments { frame_id };
606615
607616 let response = self
608− .request("scopes".to_owned(), to_value(args).ok())
609− .await?;
617+ .request("scopes".to_owned(), to_value(args).ok(), true)
618+ .await?.unwrap();
610619
611620 let body: ScopesResponseBody = from_value(response.body.unwrap()).unwrap();
612621
@@ -623,8 +632,8 @@ impl Client {
623632 };
624633
625634 let response = self
626− .request("variables".to_owned(), to_value(args).ok())
627− .await?;
635+ .request("variables".to_owned(), to_value(args).ok(), true)
636+ .await?.unwrap();
628637
629638 let body: VariablesResponseBody = from_value(response.body.unwrap()).unwrap();
630639