scheduleOnRuntimeWithId Available from 0.8.0
scheduleOnRuntimeWithId is a variant of scheduleOnRuntime 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 { scheduleOnRuntimeWithId, createWorkletRuntime } from 'react-native-worklets';
const workletRuntime = createWorkletRuntime({ name: 'background' });
scheduleOnRuntimeWithId(workletRuntime.runtimeId, (greeting: string) => {
console.log(`${greeting} from the background Worklet Runtime`);
}, 'Hello');


Type definitions
function scheduleOnRuntimeWithId<Args extends unknown[], ReturnValue>(
runtimeId: number,
worklet: (...args: Args) => ReturnValue,
...args: Args
): void;
Arguments
runtimeId
The id of the Worklet Runtime to schedule 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
- The worklet is scheduled on the Worker Runtime's Async Queue
- You can target the UI Runtime by passing UIRuntimeId as the runtime id.
- The worklet cannot be scheduled on the Worker Runtime from UI Runtime or another Worker Runtime, unless the Bundle Mode is enabled.
import { createWorkletRuntime, scheduleOnRuntimeWithId } from 'react-native-worklets';
const workletRuntime = createWorkletRuntime({ name: 'background' });
runOnUI(() => {
scheduleOnRuntimeWithId(workletRuntime.runtimeId, (greeting: string) => {
console.log(`${greeting} from the background Worklet Runtime`);
}, 'Hello'); // This will throw an error outside of Bundle Mode 🚨
});
import { createWorkletRuntime, scheduleOnRuntimeWithId } from 'react-native-worklets';
const workletRuntime = createWorkletRuntime({ name: 'background' });
const anotherWorkletRuntime = createWorkletRuntime({ name: 'anotherBackground' });
scheduleOnRuntimeWithId(workletRuntime.runtimeId, () => {
scheduleOnRuntimeWithId(anotherWorkletRuntime.runtimeId, (greeting: string) => {
console.log(`${greeting} from the background Worklet Runtime`);
}, 'Hello'); // This will throw an error outside of Bundle Mode 🚨
});