From fd62379eafde6571f126df5650b80cfda9f74229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 14 Nov 2019 04:16:57 +0100 Subject: refactor: per-worker resource table (#3306) - removes global `RESOURCE_TABLE` - resource tables are now created per `Worker` in `State` - renames `CliResource` to `StreamResource` and moves all logic related to it to `cli/ops/io.rs` - removes `cli/resources.rs` - adds `state` argument to `op_read` and `op_write` and consequently adds `stateful_minimal_op` to `State` - IMPORTANT NOTE: workers don't have access to process stdio - this is caused by fact that dropping worker would close stdout for process (because it's constructed from raw handle, which closes underlying file descriptor on drop) --- cli/ops/fetch.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'cli/ops/fetch.rs') diff --git a/cli/ops/fetch.rs b/cli/ops/fetch.rs index 143331171..a1c0fe29c 100644 --- a/cli/ops/fetch.rs +++ b/cli/ops/fetch.rs @@ -1,8 +1,9 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. use super::dispatch_json::{Deserialize, JsonOp, Value}; +use super::io::StreamResource; +use crate::http_body::HttpBody; use crate::http_util::get_client; use crate::ops::json_op; -use crate::resources; use crate::state::ThreadSafeState; use deno::*; use http::header::HeaderName; @@ -54,6 +55,7 @@ pub fn op_fetch( request = request.header(name, v); } debug!("Before fetch {}", url); + let state_ = state.clone(); let future = request.send().map_err(ErrBox::from).and_then(move |res| { let status = res.status(); let mut res_headers = Vec::new(); @@ -61,8 +63,9 @@ pub fn op_fetch( res_headers.push((key.to_string(), val.to_str().unwrap().to_owned())); } - let body = res.into_body(); - let rid = resources::add_reqwest_body(body); + let body = HttpBody::from(res.into_body()); + let mut table = state_.lock_resource_table(); + let rid = table.add("httpBody", Box::new(StreamResource::HttpBody(body))); let json_res = json!({ "bodyRid": rid, -- cgit v1.2.3