Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix run-wasm crash on trying to wait for server #1959

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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