0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

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".
This commit is contained in:
Bartek Iwańczuk 2023-09-02 08:48:21 +02:00 committed by GitHub
parent e1fb48524d
commit 83426be6ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 8 deletions

View file

@ -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

View file

@ -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<RefCell<OpState>>,
rid: ResourceId,
#[smi] rid: ResourceId,
code: Option<u16>,
reason: Option<String>,
#[string] reason: Option<String>,
) -> Result<(), AnyError> {
let resource = state
.borrow_mut()

View file

@ -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<RefCell<OpState>>,
) -> Result<Option<JsMessageData>, AnyError> {