Skip to main content

Function: runAtTargetFps()

runAtTargetFps<T>(fps, func): T | undefined

Runs the given func at the given target fps rate.

runAtTargetFps still executes the given func synchronously, so this is only useful for throttling calls to a plugin or logger.

For example, if you want to scan faces only once per second to avoid excessive CPU usage, use runAtTargetFps(1, ...).

Type Parameters​

• T

Parameters​

• fps: number

The target FPS rate at which the given function should be executed

• func

The function to execute.

Returns​

T | undefined

The result of the function if it was executed, or undefined otherwise.

Worklet​

Example​

const frameProcessor = useFrameProcessor((frame) => {
'worklet'
console.log('New Frame')
runAtTargetFps(5, () => {
'worklet'
const faces = detectFaces(frame)
console.log(`Detected a new face: ${faces[0]}`)
})
})

Defined in​

frame-processors/runAtTargetFps.ts:43