1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 00:29:09 -05:00

fix(ext/timers): some timers are not resolved (#20055)

Fixes https://github.com/denoland/deno/issues/19866
This commit is contained in:
Bartek Iwańczuk 2023-08-10 06:01:35 +02:00 committed by GitHub
parent 2507d6fa10
commit 8f854782b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View file

@ -727,3 +727,32 @@ Deno.test({
assertEquals(output, ""); assertEquals(output, "");
}, },
}); });
// Regression test for https://github.com/denoland/deno/issues/19866
Deno.test({
name: "regression for #19866",
fn: async () => {
const timeoutsFired = [];
// deno-lint-ignore require-await
async function start(n: number) {
let i = 0;
const intervalId = setInterval(() => {
i++;
if (i > 2) {
clearInterval(intervalId!);
}
timeoutsFired.push(n);
}, 20);
}
for (let n = 0; n < 100; n++) {
start(n);
}
// 3s should be plenty of time for all the intervals to fire
// but it might still be flaky on CI.
await new Promise((resolve) => setTimeout(resolve, 3000));
assertEquals(timeoutsFired.length, 300);
},
});

View file

@ -243,6 +243,7 @@ function runAfterTimeout(task, millis, timerInfo) {
resolved: false, resolved: false,
prev: scheduledTimers.tail, prev: scheduledTimers.tail,
next: null, next: null,
task,
}; };
// Add timerObject to the end of the list. // Add timerObject to the end of the list.
@ -286,7 +287,7 @@ function runAfterTimeout(task, millis, timerInfo) {
while (currentEntry !== null) { while (currentEntry !== null) {
if (currentEntry.millis <= timerObject.millis) { if (currentEntry.millis <= timerObject.millis) {
currentEntry.resolved = true; currentEntry.resolved = true;
ArrayPrototypePush(timerTasks, task); ArrayPrototypePush(timerTasks, currentEntry.task);
removeFromScheduledTimers(currentEntry); removeFromScheduledTimers(currentEntry);
if (currentEntry === timerObject) { if (currentEntry === timerObject) {