Just use a single function to spawn Gecko Driver
This commit is contained in:
parent
dcbd18885a
commit
b4192a2edc
1 changed files with 16 additions and 21 deletions
17
src/main.rs
17
src/main.rs
|
@ -32,14 +32,9 @@ struct Config {
|
|||
password: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct GeckoDriver(Child);
|
||||
|
||||
impl GeckoDriver {
|
||||
pub fn spawn(port: u16) -> Result<Self> {
|
||||
fn spawn_driver(port: u16) -> Result<Child> {
|
||||
// This is taken from the webdriver-client crate.
|
||||
let child = Command::new("geckodriver")
|
||||
// .arg("-v")
|
||||
.arg("--port")
|
||||
.arg(format!("{}", port))
|
||||
.stdin(Stdio::null())
|
||||
|
@ -50,8 +45,7 @@ impl GeckoDriver {
|
|||
|
||||
thread::sleep(Duration::new(1, 500));
|
||||
|
||||
Ok(GeckoDriver(child))
|
||||
}
|
||||
Ok(child)
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize)]
|
||||
|
@ -171,8 +165,9 @@ fn rocket() -> Rocket {
|
|||
|
||||
#[rocket::main]
|
||||
async fn main() {
|
||||
let gecko_driver =
|
||||
GeckoDriver::spawn(GECKO_DRIVER_PORT).expect("Could not find/start the Gecko Driver");
|
||||
let driver_proc =
|
||||
spawn_driver(GECKO_DRIVER_PORT).expect("Could not find/start the Gecko Driver");
|
||||
|
||||
let (tx, rx) = tokio::sync::oneshot::channel();
|
||||
let updater = tokio::spawn(update_loop(rx));
|
||||
|
||||
|
@ -183,5 +178,5 @@ async fn main() {
|
|||
.expect("Could not send update loop shutdown signal");
|
||||
let _result = updater.await;
|
||||
|
||||
drop(gecko_driver);
|
||||
drop(driver_proc);
|
||||
}
|
||||
|
|
Reference in a new issue