diff options
Diffstat (limited to 'packages/webapi/src/lib/AnimationFrame.ts')
-rw-r--r-- | packages/webapi/src/lib/AnimationFrame.ts | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/packages/webapi/src/lib/AnimationFrame.ts b/packages/webapi/src/lib/AnimationFrame.ts deleted file mode 100644 index e29d3cabf..000000000 --- a/packages/webapi/src/lib/AnimationFrame.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { - clearTimeout as nodeClearTimeout, - setTimeout as nodeSetTimeout, -} from 'node:timers' -import * as _ from './utils.js' - -const INTERNAL = { tick: 0, pool: new Map() } - -export function requestAnimationFrame< - TArgs extends any[], - TFunc extends (...args: TArgs) => any ->(callback: TFunc): number { - if (!INTERNAL.pool.size) { - nodeSetTimeout(() => { - const next = _.__performance_now() - - for (const func of INTERNAL.pool.values()) { - func(next) - } - - INTERNAL.pool.clear() - }, 1000 / 16) - } - - const func = _.__function_bind(callback, undefined) - const tick = ++INTERNAL.tick - - INTERNAL.pool.set(tick, func) - - return tick -} - -export function cancelAnimationFrame(requestId: number): void { - const timeout = INTERNAL.pool.get(requestId) - - if (timeout) { - nodeClearTimeout(timeout) - - INTERNAL.pool.delete(requestId) - } -} |