Running worklets on the UI runtime
Worklets provides three functions for running a worklet on the UI Runtime from the RN Runtime: scheduleOnUI, runOnUIAsync and runOnUISync.
They differ in whether the worklet runs asynchronously or synchronously, and in what they return to the caller.
Use the table below to pick the one that fits your case.
Comparison
scheduleOnUI | runOnUIAsync | runOnUISync | |
|---|---|---|---|
| Execution | Asynchronous | Asynchronous | Synchronous, blocks the caller until the worklet returns |
| Returns | Nothing | A Promise that resolves with the worklet's return value | The worklet's return value directly |
| Web support | ✅ | ✅ | ❌ |
| Use when | You want to run a worklet on the UI Runtime and don't need its result back | You need the worklet's result back, but don't want to block the calling thread | You need the worklet's result immediately, within the same synchronous flow |
The values returned by runOnUIAsync and runOnUISync have to be serializable.
All three functions can be called from the RN Runtime, and additionally from the UI and Worker Runtimes when Bundle Mode is enabled. See Call tables for the full matrix.