summaryrefslogtreecommitdiff
path: root/cli/state.rs
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2020-08-12 10:44:58 -0400
committerGitHub <noreply@github.com>2020-08-12 16:44:58 +0200
commitf5a4f1fdc04b24cdfbef83842b9c42b5032c4059 (patch)
treef0ead2884b3b69b287a05a82885e30a541116063 /cli/state.rs
parent6706eb551532ee6c84ad013377ac2cd91681424a (diff)
Undo JsonOpDispatcher and OpDispatcher traits (#7023)
This reverts commit f83d672ffad7afb1473bd4f9b9c645539064c620. This reverts commit d51972377c1325076704d9faec2eee6f0e024496.
Diffstat (limited to 'cli/state.rs')
-rw-r--r--cli/state.rs45
1 files changed, 36 insertions, 9 deletions
diff --git a/cli/state.rs b/cli/state.rs
index f04b577b4..35aaa7ed2 100644
--- a/cli/state.rs
+++ b/cli/state.rs
@@ -7,7 +7,6 @@ use crate::import_map::ImportMap;
use crate::metrics::Metrics;
use crate::op_error::OpError;
use crate::ops::JsonOp;
-use crate::ops::JsonOpDispatcher;
use crate::ops::MinimalOp;
use crate::permissions::Permissions;
use crate::tsc::TargetLib;
@@ -18,7 +17,6 @@ use deno_core::ModuleLoadId;
use deno_core::ModuleLoader;
use deno_core::ModuleSpecifier;
use deno_core::Op;
-use deno_core::OpDispatcher;
use deno_core::ZeroCopyBuf;
use futures::future::FutureExt;
use futures::Future;
@@ -66,7 +64,10 @@ pub struct StateInner {
}
impl State {
- pub fn stateful_json_op<D>(&self, dispatcher: D) -> impl OpDispatcher
+ pub fn stateful_json_op<D>(
+ &self,
+ dispatcher: D,
+ ) -> impl Fn(&mut deno_core::CoreIsolateState, &mut [ZeroCopyBuf]) -> Op
where
D: Fn(&State, Value, &mut [ZeroCopyBuf]) -> Result<JsonOp, OpError>,
{
@@ -74,7 +75,10 @@ impl State {
self.core_op(json_op(self.stateful_op(dispatcher)))
}
- pub fn stateful_json_op2<D>(&self, dispatcher: D) -> impl OpDispatcher
+ pub fn stateful_json_op2<D>(
+ &self,
+ dispatcher: D,
+ ) -> impl Fn(&mut deno_core::CoreIsolateState, &mut [ZeroCopyBuf]) -> Op
where
D: Fn(
&mut deno_core::CoreIsolateState,
@@ -90,7 +94,13 @@ impl State {
/// Wrap core `OpDispatcher` to collect metrics.
// TODO(ry) this should be private. Is called by stateful_json_op or
// stateful_minimal_op
- pub fn core_op(&self, dispatcher: impl OpDispatcher) -> impl OpDispatcher {
+ pub fn core_op<D>(
+ &self,
+ dispatcher: D,
+ ) -> impl Fn(&mut deno_core::CoreIsolateState, &mut [ZeroCopyBuf]) -> Op
+ where
+ D: Fn(&mut deno_core::CoreIsolateState, &mut [ZeroCopyBuf]) -> Op,
+ {
let state = self.clone();
move |isolate_state: &mut deno_core::CoreIsolateState,
@@ -101,7 +111,7 @@ impl State {
let bytes_sent_zero_copy =
zero_copy[1..].iter().map(|b| b.len()).sum::<usize>() as u64;
- let op = dispatcher.dispatch(isolate_state, zero_copy);
+ let op = dispatcher(isolate_state, zero_copy);
match op {
Op::Sync(buf) => {
@@ -144,7 +154,10 @@ impl State {
}
}
- pub fn stateful_minimal_op2<D>(&self, dispatcher: D) -> impl OpDispatcher
+ pub fn stateful_minimal_op2<D>(
+ &self,
+ dispatcher: D,
+ ) -> impl Fn(&mut deno_core::CoreIsolateState, &mut [ZeroCopyBuf]) -> Op
where
D: Fn(
&mut deno_core::CoreIsolateState,
@@ -171,7 +184,14 @@ impl State {
/// NOTE: This only works with JSON dispatcher.
/// This is a band-aid for transition to `CoreIsolate.register_op` API as most of our
/// ops require `state` argument.
- pub fn stateful_op<D>(&self, dispatcher: D) -> impl JsonOpDispatcher
+ pub fn stateful_op<D>(
+ &self,
+ dispatcher: D,
+ ) -> impl Fn(
+ &mut deno_core::CoreIsolateState,
+ Value,
+ &mut [ZeroCopyBuf],
+ ) -> Result<JsonOp, OpError>
where
D: Fn(&State, Value, &mut [ZeroCopyBuf]) -> Result<JsonOp, OpError>,
{
@@ -182,7 +202,14 @@ impl State {
-> Result<JsonOp, OpError> { dispatcher(&state, args, zero_copy) }
}
- pub fn stateful_op2<D>(&self, dispatcher: D) -> impl JsonOpDispatcher
+ pub fn stateful_op2<D>(
+ &self,
+ dispatcher: D,
+ ) -> impl Fn(
+ &mut deno_core::CoreIsolateState,
+ Value,
+ &mut [ZeroCopyBuf],
+ ) -> Result<JsonOp, OpError>
where
D: Fn(
&mut deno_core::CoreIsolateState,