diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2019-08-22 22:30:14 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-22 22:30:14 -0700 |
commit | bc467b265fbe06ace24f5d9536bd8eb36ae4a601 (patch) | |
tree | 6c1761c852398a63fe31fc912841b449fe3851c3 /cli/ops/mod.rs | |
parent | 47c216317f8eb5bf277663a732a79f6b07ba79ef (diff) |
introduce JSON serialization for ops (#2799)
Converts env(), exit(), execPath(), utime() and utimeSync() to use JSON
instead of flatbuffers.
Diffstat (limited to 'cli/ops/mod.rs')
-rw-r--r-- | cli/ops/mod.rs | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/cli/ops/mod.rs b/cli/ops/mod.rs index 92c0f8e62..240132960 100644 --- a/cli/ops/mod.rs +++ b/cli/ops/mod.rs @@ -4,6 +4,7 @@ use deno::*; mod compiler; mod dispatch_flatbuffers; +mod dispatch_json; mod dispatch_minimal; mod errors; mod fetch; @@ -23,9 +24,16 @@ mod timers; mod utils; mod workers; +// Warning! These values are duplicated in the TypeScript code (js/dispatch.ts), +// update with care. pub const OP_FLATBUFFER: OpId = 44; pub const OP_READ: OpId = 1; pub const OP_WRITE: OpId = 2; +pub const OP_EXIT: OpId = 3; +pub const OP_IS_TTY: OpId = 4; +pub const OP_ENV: OpId = 5; +pub const OP_EXEC_PATH: OpId = 6; +pub const OP_UTIME: OpId = 7; pub fn dispatch( state: &ThreadSafeState, @@ -43,10 +51,36 @@ pub fn dispatch( OP_WRITE => { dispatch_minimal::dispatch(io::op_write, state, control, zero_copy) } + OP_EXIT => dispatch_json::dispatch(os::op_exit, state, control, zero_copy), + OP_IS_TTY => { + dispatch_json::dispatch(os::op_is_tty, state, control, zero_copy) + } + OP_ENV => dispatch_json::dispatch(os::op_env, state, control, zero_copy), + OP_EXEC_PATH => { + dispatch_json::dispatch(os::op_exec_path, state, control, zero_copy) + } + OP_UTIME => { + dispatch_json::dispatch(fs::op_utime, state, control, zero_copy) + } OP_FLATBUFFER => dispatch_flatbuffers::dispatch(state, control, zero_copy), _ => panic!("bad op_id"), }; state.metrics_op_dispatched(bytes_sent_control, bytes_sent_zero_copy); - op + + match op { + Op::Sync(buf) => { + state.metrics_op_completed(buf.len()); + Op::Sync(buf) + } + Op::Async(fut) => { + use crate::futures::Future; + let state = state.clone(); + let result_fut = Box::new(fut.map(move |buf: Buf| { + state.clone().metrics_op_completed(buf.len()); + buf + })); + Op::Async(result_fut) + } + } } |