summaryrefslogtreecommitdiff
path: root/cli/ops
diff options
context:
space:
mode:
Diffstat (limited to 'cli/ops')
-rw-r--r--cli/ops/random.rs7
-rw-r--r--cli/ops/runtime.rs4
-rw-r--r--cli/ops/timers.rs13
3 files changed, 12 insertions, 12 deletions
diff --git a/cli/ops/random.rs b/cli/ops/random.rs
index 2458bc453..84e38d105 100644
--- a/cli/ops/random.rs
+++ b/cli/ops/random.rs
@@ -3,6 +3,7 @@
use deno_core::error::AnyError;
use deno_core::OpState;
use deno_core::ZeroCopyBuf;
+use rand::rngs::StdRng;
use rand::thread_rng;
use rand::Rng;
use serde_json::Value;
@@ -17,9 +18,9 @@ fn op_get_random_values(
zero_copy: &mut [ZeroCopyBuf],
) -> Result<Value, AnyError> {
assert_eq!(zero_copy.len(), 1);
- let cli_state = super::cli_state(state);
- if let Some(seeded_rng) = &cli_state.seeded_rng {
- seeded_rng.borrow_mut().fill(&mut *zero_copy[0]);
+ let maybe_seeded_rng = state.try_borrow_mut::<StdRng>();
+ if let Some(seeded_rng) = maybe_seeded_rng {
+ seeded_rng.fill(&mut *zero_copy[0]);
} else {
let mut rng = thread_rng();
rng.fill(&mut *zero_copy[0]);
diff --git a/cli/ops/runtime.rs b/cli/ops/runtime.rs
index c2ebc93f7..4c5775bcd 100644
--- a/cli/ops/runtime.rs
+++ b/cli/ops/runtime.rs
@@ -1,6 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
use crate::colors;
+use crate::metrics::Metrics;
use crate::version;
use crate::DenoSubcommand;
use deno_core::error::AnyError;
@@ -61,8 +62,7 @@ fn op_metrics(
_args: Value,
_zero_copy: &mut [ZeroCopyBuf],
) -> Result<Value, AnyError> {
- let cli_state = super::cli_state(state);
- let m = &cli_state.metrics.borrow();
+ let m = state.borrow::<Metrics>();
Ok(json!({
"opsDispatched": m.ops_dispatched,
diff --git a/cli/ops/timers.rs b/cli/ops/timers.rs
index 16220d56a..e52bb5b0e 100644
--- a/cli/ops/timers.rs
+++ b/cli/ops/timers.rs
@@ -1,5 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+use crate::global_timer::GlobalTimer;
use deno_core::error::AnyError;
use deno_core::BufVec;
use deno_core::OpState;
@@ -23,8 +24,8 @@ fn op_global_timer_stop(
_args: Value,
_zero_copy: &mut [ZeroCopyBuf],
) -> Result<Value, AnyError> {
- let cli_state = super::cli_state(state);
- cli_state.global_timer.borrow_mut().cancel();
+ let global_timer = state.borrow_mut::<GlobalTimer>();
+ global_timer.cancel();
Ok(json!({}))
}
@@ -43,11 +44,9 @@ async fn op_global_timer(
let deadline = Instant::now() + Duration::from_millis(val);
let timer_fut = {
- super::cli_state2(&state)
- .global_timer
- .borrow_mut()
- .new_timeout(deadline)
- .boxed_local()
+ let mut s = state.borrow_mut();
+ let global_timer = s.borrow_mut::<GlobalTimer>();
+ global_timer.new_timeout(deadline).boxed_local()
};
let _ = timer_fut.await;
Ok(json!({}))