runOnRuntimeAsyncWithId Available from 0.9.0
runOnRuntimeAsyncWithId is a variant of runOnRuntimeAsync 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 {
runOnRuntimeAsyncWithId,
createWorkletRuntime,
} from 'react-native-worklets';
const backgroundRuntime = createWorkletRuntime({ name: 'background' });
async function performHeavyComputation(data: number[]) {
const result = await runOnRuntimeAsyncWithId(
backgroundRuntime.runtimeId,
(numbers: number[]) => {
'worklet';
return numbers.reduce((sum, n) => sum + n, 0);
},
data
);
console.log('Computation result:', result);
}


Type definitions
function runOnRuntimeAsyncWithId<Args extends unknown[], ReturnValue>(
runtimeId: number,
worklet: (...args: Args) => ReturnValue,
...args: Args
): Promise<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
-
runOnRuntimeAsyncWithIdcan target the UI Runtime by passing UIRuntimeId as the runtime id. -
Errors thrown in the worklet will cause the Promise to reject with that error.
Call table
| Bundle Mode | RN Runtime | UI Runtime | Worker Runtime |
|---|---|---|---|
| Enabled | ✅ | ❌ | ❌ |
| Disabled | ✅ | ❌ | ❌ |
Platform compatibility
| Native | Web |
|---|---|
| ✅ | ❌ |