Skip to content

Commit

Permalink
Use futures 0.3 API (denoland#3358)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju authored and ry committed Nov 17, 2019
1 parent cb00fd6 commit 8f9a942
Show file tree
Hide file tree
Showing 36 changed files with 1,465 additions and 1,020 deletions.
1 change: 1 addition & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
max_width = 80
tab_spaces = 2
edition = "2018"
121 changes: 119 additions & 2 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 cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ base64 = "0.11.0"
byteorder = "1.3.2"
clap = "2.33.0"
dirs = "2.0.2"
futures = "0.1.29"
futures = { version = "0.3", features = [ "compat", "io-compat" ] }
http = "0.1.19"
hyper = "0.12.35"
hyper-rustls = "0.17.1"
Expand Down
6 changes: 4 additions & 2 deletions cli/compilers/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
use crate::compilers::CompiledModule;
use crate::compilers::CompiledModuleFuture;
use crate::file_fetcher::SourceFile;
use crate::futures::future::FutureExt;
use std::pin::Pin;
use std::str;

pub struct JsCompiler {}
Expand All @@ -10,14 +12,14 @@ impl JsCompiler {
pub fn compile_async(
self: &Self,
source_file: &SourceFile,
) -> Box<CompiledModuleFuture> {
) -> Pin<Box<CompiledModuleFuture>> {
let module = CompiledModule {
code: str::from_utf8(&source_file.source_code)
.unwrap()
.to_string(),
name: source_file.url.to_string(),
};

Box::new(futures::future::ok(module))
futures::future::ok(module).boxed()
}
}
8 changes: 5 additions & 3 deletions cli/compilers/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
use crate::compilers::CompiledModule;
use crate::compilers::CompiledModuleFuture;
use crate::file_fetcher::SourceFile;
use crate::futures::future::FutureExt;
use deno::ErrBox;
use regex::Regex;
use std::pin::Pin;
use std::str;

// From https://github.com/mathiasbynens/mothereff.in/blob/master/js-variables/eff.js
Expand All @@ -15,11 +17,11 @@ impl JsonCompiler {
pub fn compile_async(
self: &Self,
source_file: &SourceFile,
) -> Box<CompiledModuleFuture> {
) -> Pin<Box<CompiledModuleFuture>> {
let maybe_json_value: serde_json::Result<serde_json::Value> =
serde_json::from_str(&str::from_utf8(&source_file.source_code).unwrap());
if let Err(err) = maybe_json_value {
return Box::new(futures::future::err(ErrBox::from(err)));
return futures::future::err(ErrBox::from(err)).boxed();
}

let mut code = format!(
Expand Down Expand Up @@ -50,6 +52,6 @@ impl JsonCompiler {
name: source_file.url.to_string(),
};

Box::new(futures::future::ok(module))
futures::future::ok(module).boxed()
}
}
2 changes: 1 addition & 1 deletion cli/compilers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ pub struct CompiledModule {
}

pub type CompiledModuleFuture =
dyn Future<Item = CompiledModule, Error = ErrBox> + Send;
dyn Future<Output = Result<CompiledModule, ErrBox>> + Send;
Loading

0 comments on commit 8f9a942

Please sign in to comment.