Skip to main content
Version: 0.10-0.12

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​

import { runOnRuntimeSyncWithId, createWorkletRuntime } from 'react-native-worklets';

const workletRuntime = createWorkletRuntime({ name: 'background' });

const result = runOnRuntimeSyncWithId(workletRuntime.runtimeId, () => {
'worklet';
return 2 + 2;
}); // This will block the RN Runtime until the worklet is finished

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 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
✅❌