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
Code
Code
Colours connect each executing thread to its current code line. Recently executed lines fade over the next three ticks.
function compute() {
'worklet';
return 2 + 2;
}
const workletRuntime = createWorkletRuntime({ name: 'background' });
// Blocks the calling thread until the worklet finishes.
const result = runOnRuntimeSync(workletRuntime, compute);
console.log(result); // 4
Console 0
No output yet
Output appears here as the code runs.


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 function 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
| Mode | RN Runtime | UI Runtime | Worker Runtime |
|---|---|---|---|
| Bundle Mode | ✅ | ✅ | ✅ |
| Legacy Eval Mode | ✅ | ❌ | ❌ |
Platform compatibility
| Native | Web |
|---|---|
| ✅ | ❌ |