Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Use one runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
EverlastingBugstopper committed Jan 21, 2020
1 parent 942b3c6 commit 3e9681f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
6 changes: 3 additions & 3 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ hyper-tls = "0.4.0"
chrono = "0.4.9"
tokio = {version = "0.2", default-features = false, features = ["io-std", "time"]}
# chrome-devtools-rs = { path = "../chrome-devtools-rs" }
chrome-devtools-rs = { git = "https://github.com/everlastingbugstopper/chrome-devtools-rs", rev = "b7a0e9f" }
chrome-devtools-rs = { git = "https://github.com/everlastingbugstopper/chrome-devtools-rs", rev = "80e1ca6" }
ws = "0.9.0"
futures = "0.3"
futures-util = "0.3"
Expand Down
19 changes: 9 additions & 10 deletions src/commands/dev/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use server_config::ServerConfig;
mod headers;
use headers::{destructure_response, structure_request};

use std::thread;

use chrono::prelude::*;

use hyper::client::{HttpConnector, ResponseFuture};
Expand Down Expand Up @@ -43,15 +41,16 @@ pub fn dev(
let session_id = get_session_id()?;
let preview_id = get_preview_id(target, user, &server_config, &session_id)?;

// create a new thread to listen for devtools messages
thread::spawn(move || {
let mut runtime = TokioRuntime::new().unwrap();
runtime.block_on(socket::listen(session_id)).unwrap();
});

// spawn tokio runtime on the main thread to handle incoming HTTP requests
let mut runtime = TokioRuntime::new()?;
runtime.block_on(serve(server_config, preview_id))?;

let devtools_listener = socket::listen(session_id);
let server = serve(server_config, preview_id);

let runners = futures::future::join(devtools_listener, server);

runtime.block_on(async {
let (_, _) = runners.await;
});

Ok(())
}
Expand Down

0 comments on commit 3e9681f

Please sign in to comment.