Skip to content

Commit

Permalink
Fix run-wasm crash on trying to wait for server (#1959)
Browse files Browse the repository at this point in the history
This ruined my dev experience for re_renderer examples a bit. Not sure what made the previous hack stop working, might be a timing issue. It ended up crashing the `cargo_run_wasm` web server
  • Loading branch information
Wumpf authored Apr 25, 2023
1 parent 778c4d3 commit f0fdcf3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion run_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ license.workspace = true
publish = false

[dependencies]
cargo-run-wasm = "0.2.0"
cargo-run-wasm = "0.3.2"
pico-args = "0.5"
webbrowser = "0.8"
19 changes: 4 additions & 15 deletions run_wasm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! This is a temporary solution while we're in the process of building our own xtask tools.

use std::{net::ToSocketAddrs, time::Duration};
use std::time::Duration;

fn main() {
// TODO(cmc): Why is this not taking the full screen?
Expand Down Expand Up @@ -106,20 +106,9 @@ fn main() {
})
.expect("Failed to spawn thread");

// Wait for the server to be up before opening a browser tab.
let addr = format!("{host}:{port}")
.to_socket_addrs()
.unwrap()
.next()
.unwrap();
loop {
// TODO(cmc): this will make the webserver embedded within cargo-run-wasm complain
// a bit but eh... that's only temporary.
if std::net::TcpStream::connect(addr).is_ok() {
break;
}
std::thread::sleep(Duration::from_millis(200));
}
// It would be nice to start a webbrowser, but we can't really know when the server is ready.
// So we just sleep for a while and hope it works.
std::thread::sleep(Duration::from_millis(500));

// Open browser tab.
let viewer_url = format!("http://{host}:{port}",);
Expand Down

0 comments on commit f0fdcf3

Please sign in to comment.