Function: runAsync()
runAsync(
frame
,func
):void
Runs the given func asynchronously on a separate thread, allowing the Frame Processor to continue executing without dropping a Frame.
Only one runAsync
call will execute at the same time,
so runAsync
is not parallel, but asynchronous.
For example, if your Camera is running at 60 FPS (16ms per frame), and a heavy ML face detection Frame Processor Plugin takes 500ms to execute, you have two options:
- Run the plugin normally (synchronously in
useFrameProcessor
) but drop a lot of Frames, as we can only run at 2 FPS (500ms per frame) - Call the plugin inside
runAsync
to allow the Camera to still run at 60 FPS, but offload the heavy ML face detection plugin to the asynchronous context, where it will run at 2 FPS.
Parameters​
• frame: Frame
The current Frame of the Frame Processor.
• func
The function to execute.
Returns​
void
Note​
runAsync
cannot be used to draw to a Frame in a Skia Frame Processor.
Worklet​
Example​
const frameProcessor = useFrameProcessor((frame) => {
'worklet'
console.log('New Frame arrived!')
runAsync(frame, () => {
'worklet'
const faces = detectFaces(frame)
const face = faces[0]
console.log(`Detected a new face: ${face}`)
})
})
Defined in​
frame-processors/runAsync.ts:83