diff options
author | Andreu Botella <andreu@andreubotella.com> | 2022-05-13 10:36:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-13 10:36:31 +0200 |
commit | 3e7afb8918fd0f6cedf839a7ebaae6aaee5e66ad (patch) | |
tree | 7fcc92da290889d3d2290f6e4902ac60685aae87 /ext/web/timers.rs | |
parent | 0ee76da07b12fba38962634e65853d73adf9d4c0 (diff) |
chore(runtime): Make some ops in ext and runtime infallible. (#14589)
Co-authored-by: Aaron O'Mullan <aaron.omullan@gmail.com>
Diffstat (limited to 'ext/web/timers.rs')
-rw-r--r-- | ext/web/timers.rs | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/ext/web/timers.rs b/ext/web/timers.rs index 670df3582..eee770719 100644 --- a/ext/web/timers.rs +++ b/ext/web/timers.rs @@ -28,7 +28,7 @@ pub type StartTime = Instant; // If the High precision flag is not set, the // nanoseconds are rounded on 2ms. #[op] -pub fn op_now<TP>(state: &mut OpState, _argument: ()) -> Result<f64, AnyError> +pub fn op_now<TP>(state: &mut OpState, _argument: ()) -> f64 where TP: TimersPermission + 'static, { @@ -44,9 +44,7 @@ where subsec_nanos -= subsec_nanos % reduced_time_precision; } - let result = (seconds * 1_000) as f64 + (subsec_nanos / 1_000_000.0); - - Ok(result) + (seconds * 1_000) as f64 + (subsec_nanos / 1_000_000.0) } pub struct TimerHandle(Rc<CancelHandle>); @@ -64,11 +62,10 @@ impl Resource for TimerHandle { /// Creates a [`TimerHandle`] resource that can be used to cancel invocations of /// [`op_sleep`]. #[op] -pub fn op_timer_handle(state: &mut OpState) -> Result<ResourceId, AnyError> { - let rid = state +pub fn op_timer_handle(state: &mut OpState) -> ResourceId { + state .resource_table - .add(TimerHandle(CancelHandle::new_rc())); - Ok(rid) + .add(TimerHandle(CancelHandle::new_rc())) } /// Waits asynchronously until either `millis` milliseconds have passed or the @@ -87,14 +84,10 @@ pub async fn op_sleep( } #[op] -pub fn op_sleep_sync<TP>( - state: &mut OpState, - millis: u64, -) -> Result<(), AnyError> +pub fn op_sleep_sync<TP>(state: &mut OpState, millis: u64) where TP: TimersPermission + 'static, { state.borrow::<TP>().check_unstable(state, "Deno.sleepSync"); std::thread::sleep(Duration::from_millis(millis)); - Ok(()) } |