--- sidebar_position: 2137 # Last in the section - deprecated --- This API is deprecated and will be removed in the next major release. Use{' '} scheduleOnRuntime instead. } /> # runOnRuntime `runOnRuntime` lets you asynchronously run [workletized](../worklets-plugin/about.mdx#autoworkletization) functions on a separate worklet runtime on a separate thread. ## Reference ```javascript import { createWorkletRuntime, runOnRuntime } from 'react-native-worklets'; const workletRuntime = createWorkletRuntime({ name: 'background' }); function App() { // E.g. in event handler or in an effect // highlight-next-line runOnRuntime(workletRuntime, (greeting) => { console.log(`${greeting} from a separate thread`); // highlight-next-line })('Howdy'); // ... } ```
Type definitions ```typescript function runOnRuntime( workletRuntime: WorkletRuntime, fn: (...args: A) => R ): (...args: Parameters) => void; ```
### Arguments #### workletRuntime A reference to worklet runtime created with [`createWorkletRuntime`](./createWorkletRuntime.mdx). #### fn A reference to a function you want to execute on the worklet runtime passed as `workletRuntime`. Arguments to your function have to be passed to the function returned from `runOnRuntime` i.e. `runOnRuntime(workletRuntime, myWorklet)(10);`. ### Returns `runOnRuntime` returns a function that accepts arguments for the function passed as the first argument. :::info Don't forget to call the function returned from `runOnRuntime`. ::: ## Remarks - It's a common mistake to execute function inside of `runOnRuntime` like this: ~~`runOnRuntime(myWorklet(10))()`~~. Here, the correct usage would be `runOnRuntime(myWorklet)(10)`. - The callback passed as the argument will not be [workletized](../worklets-plugin/about.mdx#autoworkletization) automatically. You need to add `'worklet';` directive manually to allow the function to be run on the [UI thread](../tutorials/0-concurrency-model.mdx#the-react-native-model). - You may call `runOnRuntime` on any runtime, including the RN runtime, UI runtime and other worklet runtimes. - The function passed to `runOnRuntime` will be added to an execution queue on a separate thread and executed asynchronously on the specified worklet runtime. The functions will be executed in the order they were added to the queue.