Remove _async from method names since _sync are gone (#4128)

This commit is contained in:
Ryan Dahl 2020-02-25 14:42:00 -05:00 committed by GitHub
parent fe181e2b48
commit f47f3f9672
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 81 additions and 90 deletions

View File

@ -7,7 +7,7 @@ use std::str;
pub struct JsCompiler {}
impl JsCompiler {
pub async fn compile_async(
pub async fn compile(
&self,
source_file: SourceFile,
) -> Result<CompiledModule, ErrBox> {

View File

@ -10,7 +10,7 @@ static JS_RESERVED_WORDS: &str = r"^(?:do|if|in|for|let|new|try|var|case|else|en
pub struct JsonCompiler {}
impl JsonCompiler {
pub async fn compile_async(
pub async fn compile(
&self,
source_file: &SourceFile,
) -> Result<CompiledModule, ErrBox> {

View File

@ -11,8 +11,8 @@ mod wasm;
pub use js::JsCompiler;
pub use json::JsonCompiler;
pub use ts::runtime_compile_async;
pub use ts::runtime_transpile_async;
pub use ts::runtime_compile;
pub use ts::runtime_transpile;
pub use ts::TargetLib;
pub use ts::TsCompiler;
pub use wasm::WasmCompiler;

View File

@ -269,7 +269,7 @@ impl TsCompiler {
worker
}
pub async fn bundle_async(
pub async fn bundle(
&self,
global_state: GlobalState,
module_name: String,
@ -322,7 +322,7 @@ impl TsCompiler {
///
/// If compilation is required then new V8 worker is spawned with fresh TS
/// compiler.
pub async fn compile_async(
pub async fn compile(
&self,
global_state: GlobalState,
source_file: &SourceFile,
@ -641,7 +641,7 @@ async fn execute_in_thread_json(
Ok(json!(json_str))
}
pub fn runtime_compile_async<S: BuildHasher>(
pub fn runtime_compile<S: BuildHasher>(
global_state: GlobalState,
root_name: &str,
sources: &Option<HashMap<String, String, S>>,
@ -663,7 +663,7 @@ pub fn runtime_compile_async<S: BuildHasher>(
execute_in_thread_json(req_msg, global_state).boxed_local()
}
pub fn runtime_transpile_async<S: BuildHasher>(
pub fn runtime_transpile<S: BuildHasher>(
global_state: GlobalState,
sources: &HashMap<String, String, S>,
options: &Option<String>,
@ -689,7 +689,7 @@ mod tests {
use tempfile::TempDir;
#[tokio::test]
async fn test_compile_async() {
async fn test_compile() {
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
@ -707,7 +707,7 @@ mod tests {
GlobalState::mock(vec![String::from("deno"), String::from("hello.js")]);
let result = mock_state
.ts_compiler
.compile_async(mock_state.clone(), &out, TargetLib::Main)
.compile(mock_state.clone(), &out, TargetLib::Main)
.await;
assert!(result.is_ok());
assert!(result
@ -718,7 +718,7 @@ mod tests {
}
#[tokio::test]
async fn test_bundle_async() {
async fn test_bundle() {
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
@ -736,7 +736,7 @@ mod tests {
let result = state
.ts_compiler
.bundle_async(
.bundle(
state.clone(),
module_name,
Some(PathBuf::from("$deno$/bundle.js")),

View File

@ -71,7 +71,7 @@ impl WasmCompiler {
worker
}
pub async fn compile_async(
pub async fn compile(
&self,
global_state: GlobalState,
source_file: &SourceFile,
@ -84,7 +84,7 @@ impl WasmCompiler {
if let Some(m) = maybe_cached {
return Ok(m);
}
debug!(">>>>> wasm_compile_async START");
debug!(">>>>> wasm_compile START");
let base64_data = base64::encode(&source_file.source_code);
let url = source_file.url.clone();
let req_msg = serde_json::to_string(&base64_data)
@ -108,7 +108,7 @@ impl WasmCompiler {
{
cache_.lock().unwrap().insert(url.clone(), module.clone());
}
debug!("<<<<< wasm_compile_async END");
debug!("<<<<< wasm_compile END");
Ok(module)
}
}

View File

@ -127,18 +127,18 @@ impl SourceFileFetcher {
// future, because it doesn't actually do any asynchronous
// action in that path.
self
.get_source_file_async(specifier.as_url(), true, false, true)
.get_source_file(specifier.as_url(), true, false, true)
.await
.ok()
}
pub async fn fetch_source_file_async(
pub async fn fetch_source_file(
&self,
specifier: &ModuleSpecifier,
maybe_referrer: Option<ModuleSpecifier>,
) -> Result<SourceFile, ErrBox> {
let module_url = specifier.as_url().to_owned();
debug!("fetch_source_file_async specifier: {} ", &module_url);
debug!("fetch_source_file specifier: {} ", &module_url);
// Check if this file was already fetched and can be retrieved from in-process cache.
let maybe_cached_file = self.source_file_cache.get(specifier.to_string());
@ -150,7 +150,7 @@ impl SourceFileFetcher {
let specifier_ = specifier.clone();
let result = self
.get_source_file_async(
.get_source_file(
&module_url,
self.use_disk_cache,
self.no_remote,
@ -218,7 +218,7 @@ impl SourceFileFetcher {
///
/// If `cached_only` is true then this method will fail for remote files
/// not already cached.
async fn get_source_file_async(
async fn get_source_file(
&self,
module_url: &Url,
use_disk_cache: bool,
@ -248,7 +248,7 @@ impl SourceFileFetcher {
// Fetch remote file and cache on-disk for subsequent access
self
.fetch_remote_source_async(&module_url, use_disk_cache, cached_only, 10)
.fetch_remote_source(&module_url, use_disk_cache, cached_only, 10)
.await
}
@ -346,7 +346,7 @@ impl SourceFileFetcher {
///
/// Note that this is a recursive method so it can't be "async", but rather return
/// Pin<Box<..>>.
fn fetch_remote_source_async(
fn fetch_remote_source(
&self,
module_url: &Url,
use_disk_cache: bool,
@ -419,7 +419,7 @@ impl SourceFileFetcher {
// Recurse
dir
.fetch_remote_source_async(
.fetch_remote_source(
&new_module_url,
use_disk_cache,
cached_only,
@ -738,7 +738,7 @@ mod tests {
let headers_file_name_2 = headers_file_name.clone();
let result = fetcher
.get_source_file_async(&module_url, true, false, false)
.get_source_file(&module_url, true, false, false)
.await;
assert!(result.is_ok());
let r = result.unwrap();
@ -755,7 +755,7 @@ mod tests {
"{ \"content-type\": \"text/javascript\" }",
);
let result2 = fetcher_1
.get_source_file_async(&module_url, true, false, false)
.get_source_file(&module_url, true, false, false)
.await;
assert!(result2.is_ok());
let r2 = result2.unwrap();
@ -763,7 +763,7 @@ mod tests {
r2.source_code,
&b"export { printHello } from \"./print_hello.ts\";\n"[..]
);
// If get_source_file_async does not call remote, this should be JavaScript
// If get_source_file does not call remote, this should be JavaScript
// as we modified before! (we do not overwrite .headers.json due to no http fetch)
assert_eq!(&(r2.media_type), &msg::MediaType::JavaScript);
let (_, headers) = fetcher_2.http_cache.get(&module_url_1).unwrap();
@ -776,7 +776,7 @@ mod tests {
"{ \"content-type\": \"application/json\" }",
);
let result3 = fetcher_2
.get_source_file_async(&module_url_1, true, false, false)
.get_source_file(&module_url_1, true, false, false)
.await;
assert!(result3.is_ok());
let r3 = result3.unwrap();
@ -784,7 +784,7 @@ mod tests {
r3.source_code,
&b"export { printHello } from \"./print_hello.ts\";\n"[..]
);
// If get_source_file_async does not call remote, this should be JavaScript
// If get_source_file does not call remote, this should be JavaScript
// as we modified before! (we do not overwrite .headers.json due to no http fetch)
assert_eq!(&(r3.media_type), &msg::MediaType::Json);
assert!(fs::read_to_string(&headers_file_name_2)
@ -795,7 +795,7 @@ mod tests {
// and don't use cache
let fetcher = setup_file_fetcher(temp_dir.path());
let result4 = fetcher
.get_source_file_async(&module_url_2, false, false, false)
.get_source_file(&module_url_2, false, false, false)
.await;
assert!(result4.is_ok());
let r4 = result4.unwrap();
@ -821,7 +821,7 @@ mod tests {
.with_extension("headers.json");
let result = fetcher
.get_source_file_async(&module_url, true, false, false)
.get_source_file(&module_url, true, false, false)
.await;
assert!(result.is_ok());
let r = result.unwrap();
@ -837,13 +837,13 @@ mod tests {
"{ \"content-type\": \"text/typescript\" }",
);
let result2 = fetcher
.get_source_file_async(&module_url, true, false, false)
.get_source_file(&module_url, true, false, false)
.await;
assert!(result2.is_ok());
let r2 = result2.unwrap();
let expected2 = b"export const loaded = true;\n";
assert_eq!(r2.source_code, expected2);
// If get_source_file_async does not call remote, this should be TypeScript
// If get_source_file does not call remote, this should be TypeScript
// as we modified before! (we do not overwrite .headers.json due to no http
// fetch)
assert_eq!(&(r2.media_type), &msg::MediaType::TypeScript);
@ -856,7 +856,7 @@ mod tests {
// process) and don't use cache
let fetcher = setup_file_fetcher(temp_dir.path());
let result3 = fetcher
.get_source_file_async(&module_url_1, false, false, false)
.get_source_file(&module_url_1, false, false, false)
.await;
assert!(result3.is_ok());
let r3 = result3.unwrap();
@ -885,7 +885,7 @@ mod tests {
.with_extension("headers.json");
// first download
let r = fetcher.fetch_source_file_async(&specifier, None).await;
let r = fetcher.fetch_source_file(&specifier, None).await;
assert!(r.is_ok());
let result = fs::File::open(&headers_file_name);
@ -899,7 +899,7 @@ mod tests {
// `use_disk_cache` is set to false, this can be verified using source
// header file creation timestamp (should be the same as after first
// download)
let r = fetcher.fetch_source_file_async(&specifier, None).await;
let r = fetcher.fetch_source_file(&specifier, None).await;
assert!(r.is_ok());
let result = fs::File::open(&headers_file_name);
@ -937,7 +937,7 @@ mod tests {
// Test basic follow and headers recording
let result = fetcher
.get_source_file_async(&redirect_module_url, true, false, false)
.get_source_file(&redirect_module_url, true, false, false)
.await;
assert!(result.is_ok());
let mod_meta = result.unwrap();
@ -986,7 +986,7 @@ mod tests {
// Test double redirects and headers recording
let result = fetcher
.get_source_file_async(&double_redirect_url, true, false, false)
.get_source_file(&double_redirect_url, true, false, false)
.await;
assert!(result.is_ok());
let mod_meta = result.unwrap();
@ -1033,7 +1033,7 @@ mod tests {
// Test that redirect target is not downloaded twice for different redirect source.
let result = fetcher
.get_source_file_async(&double_redirect_url, true, false, false)
.get_source_file(&double_redirect_url, true, false, false)
.await;
assert!(result.is_ok());
let result = fs::File::open(&target_path);
@ -1048,7 +1048,7 @@ mod tests {
// using source header file creation timestamp (should be the same as
// after first `get_source_file`)
let result = fetcher
.get_source_file_async(&redirect_url, true, false, false)
.get_source_file(&redirect_url, true, false, false)
.await;
assert!(result.is_ok());
let result = fs::File::open(&target_path_);
@ -1074,12 +1074,12 @@ mod tests {
// Test that redirections can be limited
let result = fetcher
.fetch_remote_source_async(&double_redirect_url, false, false, 2)
.fetch_remote_source(&double_redirect_url, false, false, 2)
.await;
assert!(result.is_ok());
let result = fetcher
.fetch_remote_source_async(&double_redirect_url, false, false, 1)
.fetch_remote_source(&double_redirect_url, false, false, 1)
.await;
assert!(result.is_err());
// FIXME(bartlomieju):
@ -1097,7 +1097,7 @@ mod tests {
Url::parse("http://localhost:4545/cli/tests/002_hello.ts").unwrap();
// Remote modules are not allowed
let result = fetcher
.get_source_file_async(&module_url, true, true, false)
.get_source_file(&module_url, true, true, false)
.await;
assert!(result.is_err());
// FIXME(bartlomieju):
@ -1120,7 +1120,7 @@ mod tests {
// file hasn't been cached before
let result = fetcher
.get_source_file_async(&module_url, true, false, true)
.get_source_file(&module_url, true, false, true)
.await;
assert!(result.is_err());
// FIXME(bartlomieju):
@ -1129,21 +1129,19 @@ mod tests {
// download and cache file
let result = fetcher_1
.get_source_file_async(&module_url_1, true, false, false)
.get_source_file(&module_url_1, true, false, false)
.await;
assert!(result.is_ok());
// module is already cached, should be ok even with `cached_only`
let result = fetcher_2
.get_source_file_async(&module_url_2, true, false, true)
.get_source_file(&module_url_2, true, false, true)
.await;
assert!(result.is_ok());
drop(http_server_guard);
}
#[tokio::test]
async fn test_fetch_source_async_1() {
async fn test_fetch_source_0() {
let http_server_guard = crate::test_util::http_server();
let (_temp_dir, fetcher) = test_setup();
let module_url =
@ -1154,7 +1152,7 @@ mod tests {
.get_cache_filename(&module_url)
.with_extension("headers.json");
let result = fetcher
.fetch_remote_source_async(&module_url, false, false, 10)
.fetch_remote_source(&module_url, false, false, 10)
.await;
assert!(result.is_ok());
let r = result.unwrap();
@ -1185,7 +1183,7 @@ mod tests {
.unwrap();
let result = fetcher
.fetch_remote_source_async(&module_url, false, false, 10)
.fetch_remote_source(&module_url, false, false, 10)
.await;
assert!(result.is_ok());
let r = result.unwrap();
@ -1228,7 +1226,7 @@ mod tests {
let module_url_3_ = module_url_3.clone();
let result = fetcher
.fetch_remote_source_async(&module_url, false, false, 10)
.fetch_remote_source(&module_url, false, false, 10)
.await;
assert!(result.is_ok());
let r = result.unwrap();
@ -1237,7 +1235,7 @@ mod tests {
let (_, headers) = fetcher.http_cache.get(&module_url).unwrap();
assert_eq!(headers.get("content-type").unwrap(), "text/typescript");
let result = fetcher_1
.fetch_remote_source_async(&module_url_2, false, false, 10)
.fetch_remote_source(&module_url_2, false, false, 10)
.await;
assert!(result.is_ok());
let r2 = result.unwrap();
@ -1248,7 +1246,7 @@ mod tests {
// test unknown extension
let result = fetcher_2
.fetch_remote_source_async(&module_url_3, false, false, 10)
.fetch_remote_source(&module_url_3, false, false, 10)
.await;
assert!(result.is_ok());
let r3 = result.unwrap();
@ -1267,14 +1265,14 @@ mod tests {
// Test failure case.
let specifier =
ModuleSpecifier::resolve_url(file_url!("/baddir/hello.ts")).unwrap();
let r = fetcher.fetch_source_file_async(&specifier, None).await;
let r = fetcher.fetch_source_file(&specifier, None).await;
assert!(r.is_err());
let p =
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("js/main.ts");
let specifier =
ModuleSpecifier::resolve_url_or_path(p.to_str().unwrap()).unwrap();
let r = fetcher.fetch_source_file_async(&specifier, None).await;
let r = fetcher.fetch_source_file(&specifier, None).await;
assert!(r.is_ok());
}
@ -1286,14 +1284,14 @@ mod tests {
// Test failure case.
let specifier =
ModuleSpecifier::resolve_url(file_url!("/baddir/hello.ts")).unwrap();
let r = fetcher.fetch_source_file_async(&specifier, None).await;
let r = fetcher.fetch_source_file(&specifier, None).await;
assert!(r.is_err());
let p =
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("js/main.ts");
let specifier =
ModuleSpecifier::resolve_url_or_path(p.to_str().unwrap()).unwrap();
let r = fetcher.fetch_source_file_async(&specifier, None).await;
let r = fetcher.fetch_source_file(&specifier, None).await;
assert!(r.is_ok());
}
@ -1306,7 +1304,7 @@ mod tests {
.join("tests/001_hello.js");
let specifier =
ModuleSpecifier::resolve_url_or_path(p.to_str().unwrap()).unwrap();
let r = fetcher.fetch_source_file_async(&specifier, None).await;
let r = fetcher.fetch_source_file(&specifier, None).await;
assert!(r.is_ok());
}
@ -1550,7 +1548,7 @@ mod tests {
Url::parse("http://127.0.0.1:4545/etag_script.ts").unwrap();
let source = fetcher
.fetch_remote_source_async(&module_url, false, false, 1)
.fetch_remote_source(&module_url, false, false, 1)
.await;
assert!(source.is_ok());
let source = source.unwrap();
@ -1573,7 +1571,7 @@ mod tests {
let file_name = fetcher.http_cache.get_cache_filename(&module_url);
let _ = fs::write(&file_name, "changed content");
let cached_source = fetcher
.fetch_remote_source_async(&module_url, false, false, 1)
.fetch_remote_source(&module_url, false, false, 1)
.await
.unwrap();
assert_eq!(cached_source.source_code, b"changed content");
@ -1672,7 +1670,7 @@ mod tests {
let module_url =
Url::parse("http://127.0.0.1:4545/xTypeScriptTypes.js").unwrap();
let source = fetcher
.fetch_remote_source_async(&module_url, false, false, 1)
.fetch_remote_source(&module_url, false, false, 1)
.await;
assert!(source.is_ok());
let source = source.unwrap();
@ -1692,7 +1690,7 @@ mod tests {
let module_url =
Url::parse("http://127.0.0.1:4545/referenceTypes.js").unwrap();
let source = fetcher
.fetch_remote_source_async(&module_url, false, false, 1)
.fetch_remote_source(&module_url, false, false, 1)
.await;
assert!(source.is_ok());
let source = source.unwrap();

View File

@ -111,7 +111,7 @@ impl GlobalState {
let out = self
.file_fetcher
.fetch_source_file_async(&module_specifier, maybe_referrer)
.fetch_source_file(&module_specifier, maybe_referrer)
.await?;
// TODO(ry) Try to lift compile_lock as high up in the call stack for
@ -119,30 +119,27 @@ impl GlobalState {
let compile_lock = self.compile_lock.lock().await;
let compiled_module = match out.media_type {
msg::MediaType::Unknown => state1.js_compiler.compile_async(out).await,
msg::MediaType::Json => state1.json_compiler.compile_async(&out).await,
msg::MediaType::Unknown => state1.js_compiler.compile(out).await,
msg::MediaType::Json => state1.json_compiler.compile(&out).await,
msg::MediaType::Wasm => {
state1
.wasm_compiler
.compile_async(state1.clone(), &out)
.await
state1.wasm_compiler.compile(state1.clone(), &out).await
}
msg::MediaType::TypeScript
| msg::MediaType::TSX
| msg::MediaType::JSX => {
state1
.ts_compiler
.compile_async(state1.clone(), &out, target_lib)
.compile(state1.clone(), &out, target_lib)
.await
}
msg::MediaType::JavaScript => {
if state1.ts_compiler.compile_js {
state2
.ts_compiler
.compile_async(state1.clone(), &out, target_lib)
.compile(state1.clone(), &out, target_lib)
.await
} else {
state1.js_compiler.compile_async(out).await
state1.js_compiler.compile(out).await
}
}
}?;
@ -182,10 +179,7 @@ impl GlobalState {
#[test]
fn thread_safe() {
fn f<S: Send + Sync>(_: S) {}
f(GlobalState::mock(vec![
String::from("./deno"),
String::from("hello.js"),
]));
f(GlobalState::mock(vec![]));
}
#[test]

View File

@ -238,7 +238,7 @@ mod tests {
use super::*;
#[tokio::test]
async fn test_fetch_sync_string() {
async fn test_fetch_string() {
let http_server_guard = crate::test_util::http_server();
// Relies on external http server. See tools/http_server.py
let url =
@ -388,7 +388,7 @@ mod tests {
}
#[tokio::test]
async fn test_fetch_with_cafile_sync_string() {
async fn test_fetch_with_cafile_string() {
let http_server_guard = crate::test_util::http_server();
// Relies on external http server. See tools/http_server.py
let url =
@ -402,7 +402,6 @@ mod tests {
)))
.unwrap();
let result = fetch_once(client, &url, None).await;
if let Ok(FetchOnceResult::Code(body, headers)) = result {
assert!(!body.is_empty());
assert_eq!(headers.get("content-type").unwrap(), "application/json");

View File

@ -152,7 +152,7 @@ async fn print_file_info(
let out = global_state
.file_fetcher
.fetch_source_file_async(&module_specifier, None)
.fetch_source_file(&module_specifier, None)
.await?;
println!(
@ -303,12 +303,12 @@ async fn bundle_command(
) -> Result<(), ErrBox> {
let module_name = ModuleSpecifier::resolve_url_or_path(&source_file)?;
let global_state = GlobalState::new(flags)?;
debug!(">>>>> bundle_async START");
debug!(">>>>> bundle START");
let bundle_result = global_state
.ts_compiler
.bundle_async(global_state.clone(), module_name.to_string(), out_file)
.bundle(global_state.clone(), module_name.to_string(), out_file)
.await;
debug!(">>>>> bundle_async END");
debug!(">>>>> bundle END");
bundle_result
}

View File

@ -112,7 +112,7 @@ fn op_fetch_source_files(
let resolved_specifier = ModuleSpecifier::resolve_url(&specifier)
.expect("Invalid specifier");
file_fetcher_
.fetch_source_file_async(&resolved_specifier, ref_specifier_)
.fetch_source_file(&resolved_specifier, ref_specifier_)
.await
}
.boxed_local()
@ -130,7 +130,7 @@ fn op_fetch_source_files(
let types_specifier = ModuleSpecifier::from(types_url);
global_state
.file_fetcher
.fetch_source_file_async(&types_specifier, ref_specifier.clone())
.fetch_source_file(&types_specifier, ref_specifier.clone())
.await
.map_err(OpError::from)?
}
@ -143,7 +143,7 @@ fn op_fetch_source_files(
msg::MediaType::Wasm => {
global_state
.wasm_compiler
.compile_async(global_state.clone(), &file)
.compile(global_state.clone(), &file)
.await
.map_err(|e| OpError::other(e.to_string()))?
.code

View File

@ -1,7 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
use super::dispatch_json::{Deserialize, JsonOp, Value};
use crate::compilers::runtime_compile_async;
use crate::compilers::runtime_transpile_async;
use crate::compilers::runtime_compile;
use crate::compilers::runtime_transpile;
use crate::op_error::OpError;
use crate::state::State;
use deno_core::*;
@ -27,7 +27,7 @@ fn op_compile(
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, OpError> {
let args: CompileArgs = serde_json::from_value(args)?;
Ok(JsonOp::Async(runtime_compile_async(
Ok(JsonOp::Async(runtime_compile(
state.borrow().global_state.clone(),
&args.root_name,
&args.sources,
@ -48,7 +48,7 @@ fn op_transpile(
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, OpError> {
let args: TranspileArgs = serde_json::from_value(args)?;
Ok(JsonOp::Async(runtime_transpile_async(
Ok(JsonOp::Async(runtime_transpile(
state.borrow().global_state.clone(),
&args.sources,
&args.options,