Skip to main content
Version: 0.10-0.12

runOnUIAsync

runOnUIAsync lets you asynchronously run workletized functions on the UI thread. It returns a Promise of the worklet's return value. The Promise is resolved asynchronously, not immediately after the callback execution.

Reference​

import { runOnUIAsync } from 'react-native-worklets';

// RN Runtime, JS thread

const result: Promise<number> = runOnUIAsync((): number => {
return 1;
});

await result; // 1

Type definitions

function runOnUIAsync<Args extends unknown[], ReturnValue>(
worklet: (...args: Args) => ReturnValue,
...args: Args
): Promise<ReturnValue>;

Arguments​

worklet​

A reference to a function you want to execute on the UI thread. Arguments to your function have to be passed to the function returned from runOnUIAsync i.e. runOnUIAsync(setValue, 10);.

Remarks​

  • It's a common mistake to execute function inside of runOnUIAsync like this: runOnUIAsync(myWorklet(10)). Here, the correct usage would be runOnUIAsync(myWorklet, 10).

  • The callback passed as the argument is automatically workletized and ready to be run on the UI thread.

Call table​

ModeRN RuntimeUI RuntimeWorker Runtime
Bundle Mode✅❌❌
Legacy Eval Mode✅❌❌

What does it mean?

Platform compatibility​

NativeWeb
✅✅