Skip to content

Expose native timer ops (queueUserTimer/cancelTimer) instead of discarding them #7

Description

@marciomazza

I think it would be really useful to have a jsrun backed setTimeout and friends available somehow. (setTimeout/clearTimeout/setInterval/clearInterval)

Right now I had to hand-roll setTimeout/setInterval myself in JS using Atomics.waitAsync, which works but looks cumbersome to me.

I noticed that python_extension()'s JS bridge (src/runtime/ops.rs:278) does this:

const { ops } = Deno.core;
delete globalThis.Deno;

So it throws away queueUserTimer/cancelTimer along with everything else on Deno.core.
The timer machinery is already running inside jsrun, just out of reach.

Also noticed runner.rs already imports deno_core::stats and calls js_runtime.runtime_activity_stats_factory() to count active timers/intervals for the stats API — so you're already reaching into this exact subsystem from Rust.

Would it be reasonable to just grab the timer functions before the delete and make them available?

Perhaps something like:

const { ops, queueUserTimer, cancelTimer } = Deno.core;
globalThis.__jsrunTimers = Object.freeze({ queueUserTimer, cancelTimer });
delete globalThis.Deno;

Thanks for the great project! I'm already putting it to good use.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions