Timer APIs (setTimeout, setInterval, clearTimeout, clearInterval) for isolated-vm V8 sandbox
npm install @ricsam/isolate-timersTimer APIs with real-time execution for isolated-vm V8 sandbox.
``bash`
npm add @ricsam/isolate-timers
`typescript
import { setupTimers } from "@ricsam/isolate-timers";
const handle = await setupTimers(context);
// Timers fire automatically based on real time
// Clear all pending timers if needed
handle.clearAll();
// Dispose when done
handle.dispose();
`
- setTimeout(callback, ms, ...args) - Schedule delayed executionsetInterval(callback, ms, ...args)
- - Schedule repeated executionclearTimeout(id)
- - Cancel a timeoutclearInterval(id)
- - Cancel an interval
`javascript
// One-shot timer - fires automatically after 1 second
const timeoutId = setTimeout(() => {
console.log("Fired after 1 second!");
}, 1000);
// Repeating timer - fires automatically every 100ms
let count = 0;
const intervalId = setInterval(() => {
count++;
console.log("Tick", count);
if (count >= 5) {
clearInterval(intervalId);
}
}, 100);
// Cancel a timer
clearTimeout(timeoutId);
`
`typescript``
interface TimersHandle {
/* Clear all pending timers /
clearAll(): void;
/* Dispose the timers handle /
dispose(): void;
}
MIT