From dfdbe6a2b74a15b0a7c024411c5230153384d294 Mon Sep 17 00:00:00 2001 From: Antonio Stoilkov Date: Tue, 9 Jul 2024 10:14:45 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9C=20rename=20waitHiddenTask()=20?= =?UTF-8?q?=E2=86=92=20waitNextTaskWhileHidden()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/WorkCycleTracker.ts | 4 ++-- src/utils/{waitHiddenTask.ts => waitNextTaskWhileHidden.ts} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/utils/{waitHiddenTask.ts => waitNextTaskWhileHidden.ts} (92%) diff --git a/src/WorkCycleTracker.ts b/src/WorkCycleTracker.ts index 76b319e..6ffa1bf 100644 --- a/src/WorkCycleTracker.ts +++ b/src/WorkCycleTracker.ts @@ -1,5 +1,5 @@ import frameTracker from './frameTracker' -import waitHiddenTask from './utils/waitHiddenTask' +import waitNextTaskWhileHidden from './utils/waitNextTaskWhileHidden' import type SchedulingTask from './SchedulingTask' export default class WorkCycleTracker { @@ -23,7 +23,7 @@ export default class WorkCycleTracker { if (task.type === 'frame-based') { // we use waitHiddenTask() because requestAnimationFrame() doesn't // fire when page is hidden - await Promise.race([frameTracker.waitAfterFrame(), waitHiddenTask()]) + await Promise.race([frameTracker.waitAfterFrame(), waitNextTaskWhileHidden()]) } else if (task.type === 'idle-based') { if (typeof requestIdleCallback === 'undefined') { // todo: use waitHiddenTask() with a timeout diff --git a/src/utils/waitHiddenTask.ts b/src/utils/waitNextTaskWhileHidden.ts similarity index 92% rename from src/utils/waitHiddenTask.ts rename to src/utils/waitNextTaskWhileHidden.ts index 6df7ffb..e6e06c9 100644 --- a/src/utils/waitHiddenTask.ts +++ b/src/utils/waitNextTaskWhileHidden.ts @@ -6,7 +6,7 @@ const state = { hiddenTask: withResolvers(), } -export default async function waitHiddenTask(): Promise { +export default async function waitNextTaskWhileHidden(): Promise { if (document.visibilityState === 'hidden') { await waitNextTask()