summaryrefslogtreecommitdiff
path: root/cli/global_state.rs
diff options
context:
space:
mode:
authorGurwinder Singh <vargwin@gmail.com>2019-12-15 03:42:34 +0530
committerRy Dahl <ry@tinyclouds.org>2019-12-15 06:12:34 +0800
commit22a2afe5588ae71301db6b9a6000d241ef1e762a (patch)
tree102ebcb9aec07c0e6013f5354c940e6ecb2e0d53 /cli/global_state.rs
parent83f95fb8dfaed42eee3e1e0cd3a6e9b94f05ef2d (diff)
Use async-await at few places, fix spelling mistake (#3499)
Diffstat (limited to 'cli/global_state.rs')
-rw-r--r--cli/global_state.rs53
1 files changed, 28 insertions, 25 deletions
diff --git a/cli/global_state.rs b/cli/global_state.rs
index 981d73788..bafee47ed 100644
--- a/cli/global_state.rs
+++ b/cli/global_state.rs
@@ -15,7 +15,6 @@ use crate::permissions::DenoPermissions;
use crate::progress::Progress;
use deno::ErrBox;
use deno::ModuleSpecifier;
-use futures::future::TryFutureExt;
use std;
use std::env;
use std::future::Future;
@@ -119,17 +118,20 @@ impl ThreadSafeGlobalState {
}
pub fn fetch_compiled_module(
- self: &Self,
+ &self,
module_specifier: &ModuleSpecifier,
maybe_referrer: Option<ModuleSpecifier>,
) -> impl Future<Output = Result<CompiledModule, ErrBox>> {
let state1 = self.clone();
let state2 = self.clone();
- self
+ let source_file = self
.file_fetcher
- .fetch_source_file_async(&module_specifier, maybe_referrer)
- .and_then(move |out| match out.media_type {
+ .fetch_source_file_async(&module_specifier, maybe_referrer);
+
+ async move {
+ let out = source_file.await?;
+ let compiled_module = match out.media_type {
msg::MediaType::Unknown => state1.js_compiler.compile_async(&out),
msg::MediaType::Json => state1.json_compiler.compile_async(&out),
msg::MediaType::Wasm => {
@@ -147,28 +149,29 @@ impl ThreadSafeGlobalState {
state1.js_compiler.compile_async(&out)
}
}
- })
- .and_then(move |compiled_module| {
- if let Some(ref lockfile) = state2.lockfile {
- let mut g = lockfile.lock().unwrap();
- if state2.flags.lock_write {
- g.insert(&compiled_module);
- } else {
- let check = match g.check(&compiled_module) {
- Err(e) => return futures::future::err(ErrBox::from(e)),
- Ok(v) => v,
- };
- if !check {
- eprintln!(
- "Subresource integrety check failed --lock={}\n{}",
- g.filename, compiled_module.name
- );
- std::process::exit(10);
- }
+ }
+ .await?;
+
+ if let Some(ref lockfile) = state2.lockfile {
+ let mut g = lockfile.lock().unwrap();
+ if state2.flags.lock_write {
+ g.insert(&compiled_module);
+ } else {
+ let check = match g.check(&compiled_module) {
+ Err(e) => return Err(ErrBox::from(e)),
+ Ok(v) => v,
+ };
+ if !check {
+ eprintln!(
+ "Subresource integrity check failed --lock={}\n{}",
+ g.filename, compiled_module.name
+ );
+ std::process::exit(10);
}
}
- futures::future::ok(compiled_module)
- })
+ }
+ Ok(compiled_module)
+ }
}
#[inline]