Skip to content

Commit

Permalink
Fixup to e3b2201: use that_detached to open browser
Browse files Browse the repository at this point in the history
`open::that` can block, for example when `firefox` is the default browser
on Linux and no instance of `firefox` is running.
  • Loading branch information
ilyagr committed Mar 1, 2024
1 parent 43903d3 commit 64e9203
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion examples/poem/local-server-with-browser/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ async fn main() -> Result<(), std::io::Error> {
eprintln!("Listening at {hostname}:{port}.");
let http_address = format!("http://{hostname}:{port}/");
eprint!("Trying to launch a browser at {http_address}...");
match open::that(&http_address) {
// Using `open::that_detached` so that launching a new instance of firefox
// on Linux (for example) does not block. You can alternatively consider
// using `tokio::spawn_blocking` or the https://docs.rs/webbrowser/ crate.
match open::that_detached(&http_address) {
Ok(()) => eprintln!(" Success!"),
Err(err) => eprintln!("\nFailed to launch a browser: {err}"),
}
Expand Down

0 comments on commit 64e9203

Please sign in to comment.