From 83426be6eead06c680ae527468aeaf8723543ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 2 Sep 2023 08:48:21 +0200 Subject: 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". --- ext/web/timers.rs | 11 +++++++---- ext/websocket/lib.rs | 7 ++++--- runtime/ops/web_worker.rs | 4 +++- 3 files changed, 14 insertions(+), 8 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>, - millis: u64, - rid: ResourceId, + #[bigint] millis: u64, + #[smi] rid: ResourceId, ) -> Result { - let handle = state.borrow().resource_table.get::(rid)?; + let Ok(handle) = state.borrow().resource_table.get::(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 diff --git a/ext/websocket/lib.rs b/ext/websocket/lib.rs index 4b05131d9..32e2d18cc 100644 --- a/ext/websocket/lib.rs +++ b/ext/websocket/lib.rs @@ -5,6 +5,7 @@ use deno_core::error::invalid_hostname; use deno_core::error::type_error; use deno_core::error::AnyError; use deno_core::op; +use deno_core::op2; use deno_core::url; use deno_core::AsyncMutFuture; use deno_core::AsyncRefCell; @@ -528,12 +529,12 @@ pub async fn op_ws_send_ping( .await } -#[op(deferred)] +#[op2(async(lazy))] pub async fn op_ws_close( state: Rc>, - rid: ResourceId, + #[smi] rid: ResourceId, code: Option, - reason: Option, + #[string] reason: Option, ) -> Result<(), AnyError> { let resource = state .borrow_mut() diff --git a/runtime/ops/web_worker.rs b/runtime/ops/web_worker.rs index e62642fdd..b7b16ec1d 100644 --- a/runtime/ops/web_worker.rs +++ b/runtime/ops/web_worker.rs @@ -6,6 +6,7 @@ use crate::web_worker::WebWorkerInternalHandle; use crate::web_worker::WebWorkerType; use deno_core::error::AnyError; use deno_core::op; +use deno_core::op2; use deno_core::CancelFuture; use deno_core::OpState; @@ -37,7 +38,8 @@ fn op_worker_post_message( Ok(()) } -#[op(deferred)] +#[op2(async(lazy))] +#[serde] async fn op_worker_recv_message( state: Rc>, ) -> Result, AnyError> { -- cgit v1.2.3