1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

refactor: op_sleep uses op2 macro (#20908)

Signed-off-by: Matt Mastracci <matthew@mastracci.com>
Co-authored-by: Matt Mastracci <matthew@mastracci.com>
This commit is contained in:
Bartek Iwańczuk 2023-10-26 22:16:41 +02:00 committed by GitHub
parent 347c22dd5e
commit 96ce9cdb17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -79,13 +79,17 @@ pub fn op_timer_handle(state: &mut OpState) -> ResourceId {
/// [`TimerHandle`] resource given by `rid` has been canceled. /// [`TimerHandle`] resource given by `rid` has been canceled.
/// ///
/// If the timer is canceled, this returns `false`. Otherwise, it returns `true`. /// 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( pub async fn op_sleep(
state: Rc<RefCell<OpState>>, state: Rc<RefCell<OpState>>,
#[number] millis: u64, #[smi] millis: u64,
#[smi] rid: ResourceId, #[smi] rid: ResourceId,
) -> Result<bool, AnyError> { ) -> Result<bool, AnyError> {
let handle = state.borrow().resource_table.get::<TimerHandle>(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::<TimerHandle>(rid) else {
return Ok(false);
};
// If a timer is requested with <=100ms resolution, request the high-res timer. Since the default // 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 // Windows timer period is 15ms, this means a 100ms timer could fire at 115ms (15% late). We assume that