summaryrefslogtreecommitdiff
path: root/op_crates/timers/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'op_crates/timers/lib.rs')
-rw-r--r--op_crates/timers/lib.rs35
1 files changed, 30 insertions, 5 deletions
diff --git a/op_crates/timers/lib.rs b/op_crates/timers/lib.rs
index 047b6923c..6359b20f0 100644
--- a/op_crates/timers/lib.rs
+++ b/op_crates/timers/lib.rs
@@ -13,6 +13,9 @@ use deno_core::futures;
use deno_core::futures::channel::oneshot;
use deno_core::futures::FutureExt;
use deno_core::futures::TryFutureExt;
+use deno_core::op_async;
+use deno_core::op_sync;
+use deno_core::Extension;
use deno_core::OpState;
use deno_core::ZeroCopyBuf;
use std::cell::RefCell;
@@ -28,12 +31,34 @@ pub trait TimersPermission {
fn check_unstable(&self, state: &OpState, api_name: &'static str);
}
-pub fn init(rt: &mut deno_core::JsRuntime) {
- rt.execute(
- "deno:op_crates/timers/01_timers.js",
- include_str!("01_timers.js"),
+pub struct NoTimersPermission;
+
+impl TimersPermission for NoTimersPermission {
+ fn allow_hrtime(&mut self) -> bool {
+ false
+ }
+ fn check_unstable(&self, _: &OpState, _: &'static str) {}
+}
+
+pub fn init<P: TimersPermission + 'static>() -> Extension {
+ Extension::with_ops(
+ vec![(
+ "deno:op_crates/timers/01_timers.js",
+ include_str!("01_timers.js"),
+ )],
+ vec![
+ ("op_global_timer_stop", op_sync(op_global_timer_stop)),
+ ("op_global_timer_start", op_sync(op_global_timer_start)),
+ ("op_global_timer", op_async(op_global_timer)),
+ ("op_now", op_sync(op_now::<P>)),
+ ("op_sleep_sync", op_sync(op_sleep_sync::<P>)),
+ ],
+ Some(Box::new(|state| {
+ state.put(GlobalTimer::default());
+ state.put(StartTime::now());
+ Ok(())
+ })),
)
- .unwrap();
}
pub type StartTime = Instant;