runOnRuntimeAsync
runOnRuntimeAsync lets you asynchronously run worklet functions on a Worker Runtime.
It returns a Promise of the worklet function's return value. The Promise is resolved asynchronously, not immediately after the callback execution.
Reference
Code
Colours connect each executing thread to its current code line. Recently executed lines fade over the next three ticks.
Console 0
No output yet


Type definitions
function runOnRuntimeAsync<Args extends unknown[], ReturnValue>(
workletRuntime: WorkletRuntime,
worklet: (...args: Args) => ReturnValue,
...args: Args
): Promise<ReturnValue>;
Arguments
workletRuntime
The worklet runtime to run the worklet function on. Created with createWorkletRuntime.
worklet
A reference to a function you want to execute on the Worker Runtime. Arguments to your function have to be passed after the worklet function i.e. runOnRuntimeAsync(workletRuntime, setValue, 10);.
args
Arguments to the function you want to execute on the Worker Runtime.
Remarks
-
It's a common mistake to execute function inside of
runOnRuntimeAsynclike this:. Here, the correct usage would berunOnRuntimeAsync(workletRuntime, myWorklet(10))runOnRuntimeAsync(workletRuntime, myWorklet, 10). -
The callback passed as the argument is automatically workletized and ready to be run on the Worker Runtime.
-
Errors thrown in the worklet function will cause the Promise to reject with that error.
Call table
| Mode | RN Runtime | UI Runtime | Worker Runtime |
|---|---|---|---|
| Bundle Mode | ✅ | ✅ | ✅ |
| Legacy Eval Mode | ✅ | ❌ | ❌ |
Platform compatibility
| Native | Web |
|---|---|
| ✅ | ❌ |