summaryrefslogtreecommitdiff
path: root/ext/web/timers.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-09-02 08:48:21 +0200
committerGitHub <noreply@github.com>2023-09-02 08:48:21 +0200
commit83426be6eead06c680ae527468aeaf8723543ff2 (patch)
tree322c6659e366c8bf6029cd7082d10947d7dca9b5 /ext/web/timers.rs
parente1fb48524d2730bf7c7dfaf021bf39de2d5903bb (diff)
refactor: rewrite ops that use 'deferred' to use 'op2(async(lazy))' (#20303)
Rewrites 3 ops that used "op(deferred)" to use "op2(async(lazy))" instead. This will allow us to remove codepath for handling "deferred" ops in "deno_core".
Diffstat (limited to 'ext/web/timers.rs')
-rw-r--r--ext/web/timers.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/ext/web/timers.rs b/ext/web/timers.rs
index 6e0759a98..3a4e6cb06 100644
--- a/ext/web/timers.rs
+++ b/ext/web/timers.rs
@@ -5,6 +5,7 @@
use crate::hr_timer_lock::hr_timer_lock;
use deno_core::error::AnyError;
use deno_core::op;
+use deno_core::op2;
use deno_core::CancelFuture;
use deno_core::CancelHandle;
use deno_core::OpState;
@@ -79,13 +80,15 @@ 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`.
-#[op(deferred)]
+#[op2(async(lazy))]
pub async fn op_sleep(
state: Rc<RefCell<OpState>>,
- millis: u64,
- rid: ResourceId,
+ #[bigint] millis: u64,
+ #[smi] rid: ResourceId,
) -> Result<bool, AnyError> {
- let handle = state.borrow().resource_table.get::<TimerHandle>(rid)?;
+ let Ok(handle) = state.borrow().resource_table.get::<TimerHandle>(rid) else {
+ return Ok(true);
+ };
// 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