diff options
author | Inteon <42113979+inteon@users.noreply.github.com> | 2021-03-18 14:10:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-18 14:10:27 +0100 |
commit | 20627c91364d2a992fdfaaad7c8ae86454dbc2ed (patch) | |
tree | acef1a279e92fe072da2cce2178889f6124c47c7 /runtime/ops/mod.rs | |
parent | 0e70d9e59bc0e70f1921bb217ee00fc2e6facb69 (diff) |
refactor: update minimal ops & rename to buffer ops (#9719)
This commit rewrites "dispatch_minimal" into "dispatch_buffer".
It's part of an effort to unify JS interface for ops for both json
and minimal (buffer) ops.
Before this commit "minimal ops" could be either sync or async
depending on the return type from the op, but this commit changes
it to have separate signatures for sync and async ops (just like
in case of json ops).
Diffstat (limited to 'runtime/ops/mod.rs')
-rw-r--r-- | runtime/ops/mod.rs | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/runtime/ops/mod.rs b/runtime/ops/mod.rs index 6b64b8042..e082c5d3a 100644 --- a/runtime/ops/mod.rs +++ b/runtime/ops/mod.rs @@ -1,8 +1,5 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -mod dispatch_minimal; -pub use dispatch_minimal::MinimalOp; - pub mod crypto; pub mod fetch; pub mod fs; @@ -11,6 +8,7 @@ pub mod io; pub mod net; #[cfg(unix)] mod net_unix; +mod ops_buffer; pub mod os; pub mod permissions; pub mod plugin; @@ -36,6 +34,9 @@ use deno_core::BufVec; use deno_core::JsRuntime; use deno_core::OpState; use deno_core::ZeroCopyBuf; +use ops_buffer::buffer_op_async; +use ops_buffer::buffer_op_sync; +use ops_buffer::ValueOrVector; use std::cell::RefCell; use std::future::Future; use std::rc::Rc; @@ -62,6 +63,26 @@ where rt.register_op(name, metrics_op(name, json_op_sync(op_fn))); } +pub fn reg_buffer_async<F, R, RV>( + rt: &mut JsRuntime, + name: &'static str, + op_fn: F, +) where + F: Fn(Rc<RefCell<OpState>>, u32, BufVec) -> R + 'static, + R: Future<Output = Result<RV, AnyError>> + 'static, + RV: ValueOrVector, +{ + rt.register_op(name, metrics_op(name, buffer_op_async(op_fn))); +} + +pub fn reg_buffer_sync<F, R>(rt: &mut JsRuntime, name: &'static str, op_fn: F) +where + F: Fn(&mut OpState, u32, &mut [ZeroCopyBuf]) -> Result<R, AnyError> + 'static, + R: ValueOrVector, +{ + rt.register_op(name, metrics_op(name, buffer_op_sync(op_fn))); +} + /// `UnstableChecker` is a struct so it can be placed inside `GothamState`; /// using type alias for a bool could work, but there's a high chance /// that there might be another type alias pointing to a bool, which |