Skip to main content

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

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 🚨
});