@@ -848,14 +848,20 @@ async function executeTask(request, executionId) {
848848 admitTimer ( fnRef , true )
849849 const id = nextTimerId ++
850850 const delay = Math . max ( 1 , Math . min ( Number ( unwrapPrimitive ( msRef ) ) || 1 , timeoutMs ) )
851+ // A tick is skipped while the previous one is still in flight, so a busy isolate
852+ // cannot pile undelivered callbacks onto the worker heap.
853+ let tickInFlight = false
854+ const settleTick = ( ) => {
855+ tickInFlight = false
856+ }
851857 const nodeTimer = setInterval ( ( ) => {
852- const entry = timers . get ( id )
853- if ( ! entry ) return
858+ if ( tickInFlight || ! timers . has ( id ) ) return
854859 try {
855- fnRef . applyIgnored ( undefined , [ ] , { timeout : timeoutMs } )
860+ fnRef . apply ( undefined , [ ] , { timeout : timeoutMs } ) . then ( settleTick , settleTick )
861+ tickInFlight = true
856862 } catch {
857- // isolate disposed — callback silently dropped; the sweep on dispose
858- // clears the Node interval and releases the fn ref.
863+ // isolate disposed — the sweep on dispose clears the Node interval and
864+ // releases the fn ref.
859865 }
860866 } , delay )
861867 timers . set ( id , { nodeTimer, fnRef, recurring : true } )
@@ -969,7 +975,10 @@ async function executeTask(request, executionId) {
969975 if (typeof fn !== 'function') {
970976 throw new TypeError('setInterval requires a function callback');
971977 }
972- return __setIntervalRef.applySync(undefined, [fn, ms], {
978+ // Each tick resolves back to the host, so the wrapper keeps the callback's
979+ // return value inside the isolate.
980+ const tick = () => { fn(); };
981+ return __setIntervalRef.applySync(undefined, [tick, ms], {
973982 arguments: { reference: true },
974983 });
975984 };
0 commit comments