Make print_file_info async
@@ -51,6 +51,7 @@ use flags::DenoFlags;
use flags::DenoSubcommand;
use futures::lazy;
use futures::Future;
+use futures::future;
use log::{LevelFilter, Metadata, Record};
use std::env;
@@ -92,15 +93,15 @@ where
}
}
-pub fn print_file_info(worker: &Worker, url: &str) {
- let maybe_out =
- state::fetch_module_meta_data_and_maybe_compile(&worker.state, url, ".");
- if let Err(err) = maybe_out {
- println!("{}", err);
- return;
- }
- let out = maybe_out.unwrap();
-
+pub fn print_file_info(
+ worker: Worker,
+ url: &str,
+) -> impl Future<Item = Worker, Error = ()> {
+ worker::fetch_module_meta_data_and_maybe_compile_async(
+ &worker.state,
+ url,
+ ".",
+ ).and_then(move |out| {
println!("{} {}", ansi::bold("local:".to_string()), &(out.filename));
println!(
@@ -126,7 +127,7 @@ pub fn print_file_info(worker: &Worker, url: &str) {
}
let modules = worker.modules.lock().unwrap();
- if let Some(deps) = modules.deps(&out.module_name) {
+ if let Some(deps) = worker.modules.deps(&out.module_name) {
println!("{}{}", ansi::bold("deps:\n".to_string()), deps.name);
if let Some(ref depsdeps) = deps.deps {
for d in depsdeps {
@@ -139,6 +140,8 @@ pub fn print_file_info(worker: &Worker, url: &str) {
ansi::bold("deps:".to_string()),
);
}
+ Ok(worker)
+ }).map_err(|err| println!("{}", err))
}
fn create_worker_and_state(
@@ -195,8 +198,11 @@ fn fetch_or_info_command(
.execute_mod_async(&main_url, true)
.and_then(move |()| {
if print_info {
- print_file_info(&worker, &main_module);
+ future::Either::A(print_file_info(worker, &main_module))
+ } else {
+ future::Either::B(future::ok(worker))
}
+ }).and_then(|worker| {
worker.then(|result| {
js_check(result);
Ok(())
