From c1ec042a0011eeba2480b892a335ca7804c59180 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sun, 19 Apr 2020 23:54:46 -0400 Subject: Modify op dispatcher to include &mut Isolate argument (#4821) - Removes unnecessary RwLock and Rc around the op registry table - Preparation to move resource_table to deno_core::Isolate. - Towards #3453, #4222 --- core/examples/http_bench.rs | 64 ++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 30 deletions(-) (limited to 'core/examples') diff --git a/core/examples/http_bench.rs b/core/examples/http_bench.rs index 27fefc8bb..9e5808043 100644 --- a/core/examples/http_bench.rs +++ b/core/examples/http_bench.rs @@ -111,20 +111,22 @@ impl Isolate { F: 'static + Fn(State, u32, Option) -> Result, { let state = self.state.clone(); - let core_handler = - move |control_buf: &[u8], zero_copy_buf: Option| -> Op { - let state = state.clone(); - let record = Record::from(control_buf); - let is_sync = record.promise_id == 0; - assert!(is_sync); - - let result: i32 = match handler(state, record.rid, zero_copy_buf) { - Ok(r) => r as i32, - Err(_) => -1, - }; - let buf = RecordBuf::from(Record { result, ..record })[..].into(); - Op::Sync(buf) + let core_handler = move |_isolate: &mut deno_core::Isolate, + control_buf: &[u8], + zero_copy_buf: Option| + -> Op { + let state = state.clone(); + let record = Record::from(control_buf); + let is_sync = record.promise_id == 0; + assert!(is_sync); + + let result: i32 = match handler(state, record.rid, zero_copy_buf) { + Ok(r) => r as i32, + Err(_) => -1, }; + let buf = RecordBuf::from(Record { result, ..record })[..].into(); + Op::Sync(buf) + }; self.core_isolate.register_op(name, core_handler); } @@ -139,25 +141,27 @@ impl Isolate { >::Error: Debug, { let state = self.state.clone(); - let core_handler = - move |control_buf: &[u8], zero_copy_buf: Option| -> Op { - let state = state.clone(); - let record = Record::from(control_buf); - let is_sync = record.promise_id == 0; - assert!(!is_sync); - - let fut = async move { - let op = handler(state, record.rid, zero_copy_buf); - let result = op - .map_ok(|r| r.try_into().expect("op result does not fit in i32")) - .unwrap_or_else(|_| -1) - .await; - RecordBuf::from(Record { result, ..record })[..].into() - }; - - Op::Async(fut.boxed_local()) + let core_handler = move |_isolate: &mut deno_core::Isolate, + control_buf: &[u8], + zero_copy_buf: Option| + -> Op { + let state = state.clone(); + let record = Record::from(control_buf); + let is_sync = record.promise_id == 0; + assert!(!is_sync); + + let fut = async move { + let op = handler(state, record.rid, zero_copy_buf); + let result = op + .map_ok(|r| r.try_into().expect("op result does not fit in i32")) + .unwrap_or_else(|_| -1) + .await; + RecordBuf::from(Record { result, ..record })[..].into() }; + Op::Async(fut.boxed_local()) + }; + self.core_isolate.register_op(name, core_handler); } } -- cgit v1.2.3