Skip to content

Commit

Permalink
fix(node-wasm): workaround to clean extra message from worker
Browse files Browse the repository at this point in the history
  • Loading branch information
zvolin committed Oct 18, 2024
1 parent a435e78 commit 7fa4dc4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions node-wasm/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl NodeClient {

let worker = WorkerClient::new(port)?;

// todo: refactor when oneshots are implemented
// keep pinging worker until it responds.
// NOTE: there is a possibility that worker can take longer than a timeout
// to send his response. Client will then send another ping and read previous
Expand All @@ -71,6 +72,9 @@ impl NodeClient {
break;
}
}
// wait another timeout to read potential extra response from worker that
// could be caused by the loop above
let _ = timeout(200, worker.recv()).await;

debug!("Connected to worker");

Expand Down
12 changes: 12 additions & 0 deletions node-wasm/src/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,18 @@ impl WorkerClient {

Ok(worker_response)
}

// todo: remove when oneshots are implemented, used in workaround for initial worker connection
pub(crate) async fn recv(&self) -> Result<WorkerResponse> {
let mut response_channel = self.response_channel.lock().await;
let worker_response = response_channel
.recv()
.await
.expect("response channel should never drop")
.context("error receiving command")?;

Ok(worker_response)
}
}

impl Drop for WorkerClient {
Expand Down

0 comments on commit 7fa4dc4

Please sign in to comment.