runOnRuntimeSync
runOnRuntimeSync lets you run a workletized function synchronously on a Worker Runtime. It blocks the calling thread until the function returns. If another thread is running a worklet function on that runtime, it waits until the runtime is free.
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
| RN Runtime | UI Runtime | Worker Runtime |
|---|---|---|
| ✅ | ✅ | ✅ |
Platform compatibility
| Native | Web |
|---|---|
| ✅ | ❌ |