diff options
author | andy finch <andyfinch7@gmail.com> | 2019-06-13 23:43:54 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-06-13 20:43:54 -0700 |
commit | dc60fe9f300043f191286ef804a365e16e455f87 (patch) | |
tree | c6b74e9faa6f26745b8770a18d0ae46ee34f3774 /cli/dispatch_minimal.rs | |
parent | fdd2eb538327ee3f50fe2869320411191830c985 (diff) |
Refactor dispatch handling (#2452)
Promise id is now created in core and passed back to JS.
Diffstat (limited to 'cli/dispatch_minimal.rs')
-rw-r--r-- | cli/dispatch_minimal.rs | 45 |
1 files changed, 15 insertions, 30 deletions
diff --git a/cli/dispatch_minimal.rs b/cli/dispatch_minimal.rs index 0e20d3b1a..643fdaed9 100644 --- a/cli/dispatch_minimal.rs +++ b/cli/dispatch_minimal.rs @@ -6,6 +6,7 @@ //! message or a "minimal" message. use crate::state::ThreadSafeState; use deno::Buf; +use deno::CoreOp; use deno::Op; use deno::PinnedBuf; use futures::Future; @@ -17,7 +18,6 @@ const OP_WRITE: i32 = 2; #[derive(Copy, Clone, Debug, PartialEq)] // This corresponds to RecordMinimal on the TS side. pub struct Record { - pub promise_id: i32, pub op_id: i32, pub arg: i32, pub result: i32, @@ -25,15 +25,9 @@ pub struct Record { impl Into<Buf> for Record { fn into(self) -> Buf { - let vec = vec![ - DISPATCH_MINIMAL_TOKEN, - self.promise_id, - self.op_id, - self.arg, - self.result, - ]; + let vec = vec![DISPATCH_MINIMAL_TOKEN, self.op_id, self.arg, self.result]; let buf32 = vec.into_boxed_slice(); - let ptr = Box::into_raw(buf32) as *mut [u8; 5 * 4]; + let ptr = Box::into_raw(buf32) as *mut [u8; 4 * 4]; unsafe { Box::from_raw(ptr) } } } @@ -45,36 +39,32 @@ pub fn parse_min_record(bytes: &[u8]) -> Option<Record> { let p = bytes.as_ptr(); #[allow(clippy::cast_ptr_alignment)] let p32 = p as *const i32; - let s = unsafe { std::slice::from_raw_parts(p32, bytes.len() / 4) }; + let s = unsafe { std::slice::from_raw_parts(p32, bytes.len() / 3) }; - if s.len() < 5 { + if s.len() < 4 { return None; } let ptr = s.as_ptr(); - let ints = unsafe { std::slice::from_raw_parts(ptr, 5) }; + let ints = unsafe { std::slice::from_raw_parts(ptr, 4) }; if ints[0] != DISPATCH_MINIMAL_TOKEN { return None; } Some(Record { - promise_id: ints[1], - op_id: ints[2], - arg: ints[3], - result: ints[4], + op_id: ints[1], + arg: ints[2], + result: ints[3], }) } #[test] fn test_parse_min_record() { - let buf = vec![ - 0xFE, 0xCA, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, - ]; + let buf = vec![0xFE, 0xCA, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0]; assert_eq!( parse_min_record(&buf), Some(Record { - promise_id: 1, - op_id: 2, - arg: 3, - result: 4, + op_id: 1, + arg: 2, + result: 3, }) ); @@ -89,8 +79,7 @@ pub fn dispatch_minimal( state: &ThreadSafeState, mut record: Record, zero_copy: Option<PinnedBuf>, -) -> Op { - let is_sync = record.promise_id == 0; +) -> CoreOp { let min_op = match record.op_id { OP_READ => ops::read(record.arg, zero_copy), OP_WRITE => ops::write(record.arg, zero_copy), @@ -115,11 +104,7 @@ pub fn dispatch_minimal( state.metrics_op_completed(buf.len()); Ok(buf) })); - if is_sync { - Op::Sync(fut.wait().unwrap()) - } else { - Op::Async(fut) - } + Op::Async(fut) } mod ops { |