Skip to content
Permalink
Browse files

workers should also be normal isolates

  • Loading branch information...
ry committed Mar 12, 2019
1 parent b02d788 commit 240a9feae1b6cd7069bcc6dc410c2a4e8231e0b9
Showing with 10 additions and 8 deletions.
  1. +0 −2 src/cli.rs
  2. +4 −1 src/isolate.rs
  3. +6 −5 src/workers.rs
@@ -22,8 +22,6 @@ use std::time::Instant;
// a heap allocated opaque sequence of bytes. Usually a flatbuffer message.
pub type Buf = Box<[u8]>;

pub type Isolate = deno_core::Isolate<Buf, Cli>;

pub type CliOp = Op<Buf>;

/// Implements deno_core::Behavior for the main Deno command-line.
@@ -1,19 +1,22 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use crate::cli::Buf;
use crate::cli::Cli;
use crate::cli::Isolate as CoreIsolate;
use crate::compiler::compile_sync;
use crate::compiler::ModuleMetaData;
use crate::errors::DenoError;
use crate::errors::RustOrJsError;
use crate::isolate_state::IsolateState;
use crate::js_errors;
use crate::msg;
use deno_core;
use deno_core::deno_mod;
use deno_core::JSError;
use futures::Async;
use futures::Future;
use std::sync::Arc;

type CoreIsolate = deno_core::Isolate<Buf, Cli>;

/// Wraps deno_core::Isolate to provide source maps, ops for the CLI, and
/// high-level module loading
pub struct Isolate {
@@ -1,14 +1,15 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use crate::cli::Buf;
use crate::cli::Cli;
use crate::cli::Isolate;
use crate::flags::DenoFlags;
use crate::isolate::Isolate;
use crate::isolate_init::IsolateInit;
use crate::isolate_state::IsolateState;
use crate::isolate_state::WorkerChannels;
use crate::js_errors::JSErrorColor;
use crate::permissions::DenoPermissions;
use crate::resources;
use crate::tokio_util;
use deno_core::JSError;
use futures::future::lazy;
use futures::sync::mpsc;
@@ -47,7 +48,7 @@ impl Worker {
}

pub fn execute(&self, js_source: &str) -> Result<(), JSError> {
self.isolate.execute("<anonymous>", js_source)
self.isolate.execute(js_source)
}
}

@@ -78,7 +79,7 @@ pub fn spawn(

let _tid = builder
.spawn(move || {
tokio::runtime::current_thread::run(lazy(move || {
tokio_util::run(lazy(move || {
let (worker, external_channels) =
Worker::new(init, flags, argv, permissions);
let resource = resources::add_worker(external_channels);
@@ -94,7 +95,7 @@ pub fn spawn(

worker.then(move |r| -> Result<(), ()> {
resource.close();
println!("workers.rs after resource close");
debug!("workers.rs after resource close");
if let Err(err) = r {
eprintln!("{}", JSErrorColor(&err).to_string());
std::process::exit(1);
@@ -103,7 +104,7 @@ pub fn spawn(
})
}));

println!("workers.rs after spawn");
debug!("workers.rs after spawn");
}).unwrap();

c.wait().unwrap()

0 comments on commit 240a9fe

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.