UNPKG

react-native-vision-camera

Version:

VisionCamera is the fastest and most powerful Camera for react-native.

34 lines (33 loc) 945 B
import { useMemo } from 'react'; import { VisionCameraWorkletsProxy } from '../third-party/VisionCameraWorkletsProxy'; /** * Use an {@linkcode AsyncRunner}. * An {@linkcode AsyncRunner} can be used to asynchronously * run code in a Frame Processor on a separate, non-blocking * Thread. * @example * ```ts * function App() { * const asyncRunner = useAsyncRunner() * const frameOutput = useFrameOutput({ * onFrame(frame) { * 'worklet' * const wasHandled = asyncRunner.runAsync(() => { * 'worklet' * doSomeHeavyProcessing(frame) * // Async task finished - dispose the Frame now. * frame.dispose() * }) * * if (!wasHandled) { * // `asyncRunner` is busy - drop this Frame! * frame.dispose() * } * } * }) * } * ``` */ export function useAsyncRunner() { return useMemo(() => VisionCameraWorkletsProxy.createAsyncRunner(), []); }