Skip to main content
Version: 0.10-0.12

runOnRuntimeSync

Available from 0.8.0

runOnRuntimeSync lets you run a workletized function synchronously on a Worker Runtime. It's blocking - meaning that it can preempt the runtime from a thread that's currently executing it.

Reference​

import { runOnRuntimeSync, createWorkletRuntime } from 'react-native-worklets';

const workletRuntime = createWorkletRuntime({ name: 'background' });

const result = runOnRuntimeSync(workletRuntime, () => {
'worklet';
return 2 + 2;
}); // This will block the RN Runtime until the worklet is finished

console.log(result); // 4

Type definitions

function runOnRuntimeSync<Args extends unknown[], ReturnValue>(
workletRuntime: WorkletRuntime,
worklet: (...args: Args) => ReturnValue,
...args: Args
): ReturnValue;

Arguments​

workletRuntime​

The worklet runtime to run the worklet on.

worklet​

A reference to a function you want to execute on the Worker Runtime.

args​

Arguments to the function you want to execute on the Worker Runtime.

Call table​

ModeRN RuntimeUI RuntimeWorker Runtime
Bundle Mode✅✅✅
Legacy Eval Mode✅❌❌

What does it mean?

Platform compatibility​

NativeWeb
✅❌