From 96ce9cdb17f6ed2dc449754d762ecccbd98e4814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 26 Oct 2023 22:16:41 +0200 Subject: refactor: op_sleep uses op2 macro (#20908) Signed-off-by: Matt Mastracci Co-authored-by: Matt Mastracci --- ext/web/timers.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'ext/web') diff --git a/ext/web/timers.rs b/ext/web/timers.rs index 7c83e8f37..6b00296ff 100644 --- a/ext/web/timers.rs +++ b/ext/web/timers.rs @@ -79,13 +79,17 @@ pub fn op_timer_handle(state: &mut OpState) -> ResourceId { /// [`TimerHandle`] resource given by `rid` has been canceled. /// /// If the timer is canceled, this returns `false`. Otherwise, it returns `true`. -#[op2(async(deferred), fast)] +#[op2(async(lazy), fast)] pub async fn op_sleep( state: Rc>, - #[number] millis: u64, + #[smi] millis: u64, #[smi] rid: ResourceId, ) -> Result { - let handle = state.borrow().resource_table.get::(rid)?; + // If the timer is not present in the resource table it was cancelled before + // this op was polled. + let Ok(handle) = state.borrow().resource_table.get::(rid) else { + return Ok(false); + }; // If a timer is requested with <=100ms resolution, request the high-res timer. Since the default // Windows timer period is 15ms, this means a 100ms timer could fire at 115ms (15% late). We assume that -- cgit v1.2.3