Skip to main content
Version: Unreleased

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

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​

  • runOnRuntimeSyncWithId can target the UI Runtime by passing UIRuntimeId as the runtime id.

Call table​

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

What does it mean?

Platform compatibility​

NativeWeb
✅❌