From 5cc7430bb6148b7c6b607dd77782aada964a7634 Mon Sep 17 00:00:00 2001 From: Antonio Stoilkov Date: Mon, 5 Feb 2024 13:00:02 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20improve=20runPostTask()=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playground/playground.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/playground/playground.ts b/playground/playground.ts index a633ccb..5ee8e61 100644 --- a/playground/playground.ts +++ b/playground/playground.ts @@ -46,12 +46,15 @@ document.querySelector('#post-task-background')!.addEventListener('click', () => }) async function runPostTask(priority: 'user-blocking' | 'user-visible' | 'background') { - for (let i = 0; i < 5; i++) { + const totalTime = 1000 + const singleTaskTime = 2 + const iterations = Math.round(totalTime / singleTaskTime) + for (let i = 0; i < iterations; i++) { // @ts-ignore scheduler.postTask( () => { const start = Date.now() - while (Date.now() - start < 200) {} + while (Date.now() - start < singleTaskTime) {} }, { priority,