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.
Remarks
runOnRuntimeSynccan only be called on the RN Runtime unless the Bundle Mode is enabled.
import { createWorkletRuntime, runOnRuntimeSync } from 'react-native-worklets';
const workletRuntime = createWorkletRuntime({ name: 'background' });
runOnUI(() => {
runOnRuntimeSync(workletRuntime, (greeting: string) => {
console.log(`${greeting} from the background Worklet Runtime`);
}, 'Hello'); // This will throw an error outside of Bundle Mode 🚨
});
import { createWorkletRuntime, scheduleOnRuntime } from 'react-native-worklets';
const workletRuntime = createWorkletRuntime({ name: 'background' });
const anotherWorkletRuntime = createWorkletRuntime({ name: 'anotherBackground' });
runOnRuntimeSync(anotherWorkletRuntime, () => {
runOnRuntimeSync(workletRuntime, (greeting: string) => {
console.log(`${greeting} from the background Worklet Runtime`);
}, 'Hello'); // This will throw an error outside of Bundle Mode 🚨
});