Skip to content

Commit

Permalink
Spawn thread when fetching remote lib.
Browse files Browse the repository at this point in the history
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
  • Loading branch information
kitsonk and bartlomieju committed Feb 15, 2020
1 parent 4d05b4e commit d905a6f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
2 changes: 0 additions & 2 deletions cli/js/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
// Either of these functions must be called when creating isolate
// to properly setup runtime.

// <reference types="../../deno_typescript/globals" />

// NOTE: this import has side effects!
import "./ts_global.d.ts";

Expand Down
1 change: 0 additions & 1 deletion cli/js/compiler_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ const ignoredCompilerOptions: readonly string[] = [
"inlineSources",
"init",
"isolatedModules",
// "lib",
"listEmittedFiles",
"listFiles",
"mapRoot",
Expand Down
3 changes: 2 additions & 1 deletion cli/js/lib.deno.ns.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

/// <reference no-default-lib="true" />
/// <reference lib="esnext" />

declare namespace Deno {
/** The current process id of the runtime. */
Expand Down Expand Up @@ -247,7 +248,7 @@ declare namespace Deno {
/** UNSTABLE: might move to Deno.symbols */
export const EOF: unique symbol;

/** UNSTABLE: might move to Deno.symbols */
/** UNSTABLE: might move to Deno.symbols */
export type EOF = typeof EOF;

/** UNSTABLE: maybe remove "SEEK_" prefix. Maybe capitalization wrong. */
Expand Down
5 changes: 5 additions & 0 deletions cli/js/lib.deno.shared_globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-interface, @typescript-eslint/no-explicit-any */

/// <reference no-default-lib="true" />
// TODO: we need to remove this, but Fetch::Response::Body implements Reader
// which requires Deno.EOF, and we shouldn't be leaking that, but https_proxy
// at the least requires the Reader interface on Body, which it shouldn't
/// <reference lib="deno.ns" />
/// <reference lib="esnext" />

// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope

Expand Down
18 changes: 13 additions & 5 deletions cli/ops/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
use super::dispatch_json::Deserialize;
use super::dispatch_json::JsonOp;
use super::dispatch_json::Value;
use crate::file_fetcher::SourceFile;
use crate::futures::future::try_join_all;
use crate::msg;
use crate::ops::json_op;
use crate::state::State;
use crate::tokio_util;
use deno_core::Loader;
use deno_core::*;

Expand Down Expand Up @@ -174,13 +176,19 @@ fn op_fetch_remote_asset(
let args: FetchRemoteAssetArgs = serde_json::from_value(args)?;
debug!("args.name: {}", args.name);

let (sender, receiver) =
std::sync::mpsc::sync_channel::<Result<SourceFile, ErrBox>>(1);
let global_state = state.borrow().global_state.clone();
let source_file = futures::executor::block_on(
global_state
// FIXME(bartlomieju): shouldn't spawn new thread
std::thread::spawn(move || {
let mut rt = tokio_util::create_basic_runtime();
let fut = global_state
.file_fetcher
.fetch_remote_asset_async(&args.name),
)
.unwrap();
.fetch_remote_asset_async(&args.name);
let res = rt.block_on(fut);
sender.send(res).unwrap();
});
let source_file = receiver.recv().unwrap()?;
let out = json!({
"url": source_file.url.to_string(),
"filename": source_file.filename.to_str().unwrap(),
Expand Down

0 comments on commit d905a6f

Please sign in to comment.