Skip to main content

scheduleOnRuntime

scheduleOnRuntime lets you schedule a worklet to be executed on a Worker Runtime.

Reference

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

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

scheduleOnRuntime(workletRuntime, (greeting: string) => {
console.log(`${greeting} from the background Worklet Runtime`);
}, 'Hello');

Type definitions

function scheduleOnRuntime<Args extends unknown[], ReturnValue>(
workletRuntime: WorkletRuntime,
worklet: (...args: Args) => ReturnValue,
...args: Args
): void

Arguments

workletRuntime

The worklet runtime to schedule the worklet on.

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, scheduleOnRuntime } from 'react-native-worklets';

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

runOnUI(() => {
scheduleOnRuntime(workletRuntime, (greeting: string) => {
console.log(`${greeting} from the background Worklet Runtime`);
}, 'Hello'); // This will throw an error outside of Bundle Mode 🚨
});
import { createWorkletRuntime, scheduleOnRuntime } from 'react-native-worklets';

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

scheduleOnRuntime(anotherWorkletRuntime, () => {
scheduleOnRuntime(workletRuntime, (greeting: string) => {
console.log(`${greeting} from the background Worklet Runtime`);
}, 'Hello'); // This will throw an error 🚨
});