summaryrefslogtreecommitdiff
path: root/cli/ops/timers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/ops/timers.rs')
-rw-r--r--cli/ops/timers.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/cli/ops/timers.rs b/cli/ops/timers.rs
index 74edc7267..841cdf289 100644
--- a/cli/ops/timers.rs
+++ b/cli/ops/timers.rs
@@ -25,6 +25,7 @@ use std::cell::RefCell;
use std::future::Future;
use std::pin::Pin;
use std::rc::Rc;
+use std::thread::sleep;
use std::time::Duration;
use std::time::Instant;
@@ -77,6 +78,7 @@ pub fn init(rt: &mut deno_core::JsRuntime) {
super::reg_json_sync(rt, "op_global_timer_start", op_global_timer_start);
super::reg_json_async(rt, "op_global_timer", op_global_timer);
super::reg_json_sync(rt, "op_now", op_now);
+ super::reg_json_sync(rt, "op_sleep_sync", op_sleep_sync);
}
fn op_global_timer_stop(
@@ -157,3 +159,19 @@ fn op_now(
"subsecNanos": subsec_nanos,
}))
}
+
+#[derive(Deserialize)]
+struct SleepArgs {
+ millis: u64,
+}
+
+fn op_sleep_sync(
+ state: &mut OpState,
+ args: Value,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result<Value, AnyError> {
+ super::check_unstable(state, "Deno.sleepSync");
+ let args: SleepArgs = serde_json::from_value(args)?;
+ sleep(Duration::from_millis(args.millis));
+ Ok(json!({}))
+}