Skip to content

Commit

Permalink
docs: Update runAsync and runAtTargetFps docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed May 1, 2024
1 parent 2e2d9b4 commit af2707e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion docs/docs/guides/FRAME_PROCESSORS_INTERACTING.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ For example, if your Camera is running at **30 FPS**, your Frame Processor has *

### Running asynchronously

For longer running processing, you can use [`runAsync(..)`](/docs/api/#runasync) to run code asynchronously on a different Thread:
For longer running processing, you can use [`runAsync(..)`](/docs/api/#runasync) to run code asynchronously on a different Thread.
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 can 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.

```ts
const frameProcessor = useFrameProcessor((frame) => {
Expand All @@ -96,6 +99,7 @@ const frameProcessor = useFrameProcessor((frame) => {
runAsync(frame, () => {
'worklet'
console.log("I'm running asynchronously, possibly at a lower FPS rate!")
const faces = detectFaces(frame)
})
}, [])
```
Expand All @@ -112,6 +116,7 @@ const frameProcessor = useFrameProcessor((frame) => {
runAtTargetFps(2, () => {
'worklet'
console.log("I'm running synchronously at 2 FPS!")
const brightness = detectBrightness(frame)
})
}, [])
```
Expand Down

0 comments on commit af2707e

Please sign in to comment.