runOnRuntimeSyncWithId
Available from 0.8.0
runOnRuntimeSyncWithId is a variant of runOnRuntimeSync where you use the runtime's id instead of the runtime object. It's useful when you don't have access to the runtime object, but you know its id.
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 = runOnRuntimeSyncWithId(
workletRuntime.runtimeId,
compute
);
console.log(result); // 4
Console 0
No output yet
Output appears here as the code runs.


Type definitions
function runOnRuntimeSyncWithId<Args extends unknown[], ReturnValue>(
runtimeId: number,
worklet: (...args: Args) => ReturnValue,
...args: Args
): ReturnValue;
Arguments
runtimeId
The id of the Worklet Runtime to run the worklet function on. You can get the id from the runtime object by accessing its runtimeId property.
worklet
A reference to a function you want to execute on the Worklet Runtime.
args
Arguments to the function you want to execute on the Worklet Runtime.
Remarks
runOnRuntimeSyncWithIdcan target the UI Runtime by passing UIRuntimeId as the runtime id.
Call table
| Mode | RN Runtime | UI Runtime | Worker Runtime |
|---|---|---|---|
| Bundle Mode | ✅ | ✅ | ✅ |
| Legacy Eval Mode | ✅ | ❌ | ❌ |
Platform compatibility
| Native | Web |
|---|---|
| ✅ | ❌ |