Skip to content

Commit

Permalink
Big refactor: Use tokio default runtime
Browse files Browse the repository at this point in the history
This makes all of the ops thread safe.

Now Deno is multithreaded.

Preliminary work for denoland#733.
  • Loading branch information
ry committed Sep 22, 2018
1 parent 3ad48bd commit 2388d35
Show file tree
Hide file tree
Showing 6 changed files with 381 additions and 222 deletions.
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ main_extern = [
"$rust_build:tempfile",
"$rust_build:rand",
"$rust_build:tokio",
"$rust_build:tokio_executor",
"$rust_build:url",
"$rust_build:remove_dir_all",
"$rust_build:dirs",
Expand Down
29 changes: 25 additions & 4 deletions src/flags.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
use libc::c_int;
use libdeno;
use log;
use std::ffi::CStr;
use std::ffi::CString;
use std::mem;
use std::process::exit;
use std::vec::Vec;
use version;

// Creates vector of strings, Vec<String>
#[cfg(test)]
Expand All @@ -24,6 +27,24 @@ pub struct DenoFlags {
pub deps_flag: bool,
}

pub fn process(flags: &DenoFlags) {
if flags.help {
print_usage();
exit(0);
}

if flags.version {
version::print_version();
exit(0);
}

let mut log_level = log::LevelFilter::Info;
if flags.log_debug {
log_level = log::LevelFilter::Debug;
}
log::set_max_level(log_level);
}

pub fn print_usage() {
println!(
"Usage: deno script.ts
Expand All @@ -41,6 +62,8 @@ pub fn print_usage() {

// Parses flags for deno. This does not do v8_set_flags() - call that separately.
pub fn set_flags(args: Vec<String>) -> (DenoFlags, Vec<String>) {
let args = v8_set_flags(args);

let mut flags = DenoFlags::default();
let mut rest = Vec::new();
let mut arg_iter = args.iter();
Expand Down Expand Up @@ -154,8 +177,7 @@ fn parse_core_args(args: Vec<String>) -> (Vec<String>, Vec<String>) {
}

true
})
.collect();
}).collect();

// Replace args being sent to V8
for idx in 0..args.len() {
Expand Down Expand Up @@ -222,7 +244,6 @@ pub fn v8_set_flags(args: Vec<String>) -> Vec<String> {
let cstr = CStr::from_ptr(*ptr as *const i8);
let slice = cstr.to_str().unwrap();
slice.to_string()
})
.chain(rest.into_iter())
}).chain(rest.into_iter())
.collect()
}
Loading

0 comments on commit 2388d35

Please sign in to comment.