Skip to content

Commit f6f9f8b

Browse files
committed
Add timeout-based task splitter
So the loop won't hold the thread hostage for longer than 100ms at a time.
1 parent 6933a7a commit f6f9f8b

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

source/features/show-whitespace.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,14 @@ function showWhiteSpacesOn(line: Element): void {
4949
}
5050

5151
async function run(): Promise<void> {
52+
let timeKeeper = Date.now();
5253
for (const line of select.all('.blob-code-inner')) {
5354
line.classList.add('rgh-showing-whitespace');
5455
showWhiteSpacesOn(line);
56+
if (timeKeeper + 100 < Date.now()) {
57+
await new Promise(resolve => setTimeout(resolve, 50));
58+
timeKeeper = Date.now();
59+
}
5560
}
5661
}
5762

0 commit comments

Comments
 (0)