Call tables
Call tables are quick references that show where a given scheduling function can be called from, depending on whether Bundle Mode is enabled or not.
Why does Bundle Mode matter?
Without Bundle Mode, Worklet Runtimes only have a subset of functionalities of the RN Runtime, due to limitations of serialization of worklets. With Bundle Mode enabled, every runtime has access to the full JavaScript bundle, so most threading APIs become available on all runtimes.
How to read a call table
Take scheduleOnUI as an example:
| Bundle Mode | RN Runtime | UI Runtime | Worker Runtime |
|---|---|---|---|
| Enabled | ✅ | ✅ | ✅ |
| Disabled | ✅ | ❌ | ❌ |
A green check mark in the table means that the function can be called from that runtime, while a red cross means that calling the function from that runtime will throw an error. So in this case, scheduleOnUI can be called from any runtime when Bundle Mode is on, but only from the RN Runtime when Bundle Mode is off:
import {
scheduleOnUI,
scheduleOnRuntime,
createWorkletRuntime,
} from 'react-native-worklets';
const workerRuntime = createWorkletRuntime();
// We are on RN Runtime -
// this is always fine
scheduleOnUI(/*...*/);
scheduleOnUI(() => {
// We are on the UI Runtime -
// this is only fine with Bundle Mode enabled
scheduleOnUI(/*...*/);
});
scheduleOnRuntime(workerRuntime, () => {
// We are on the Worker Runtime -
// this is only fine with Bundle Mode enabled
scheduleOnUI(/*...*/);
});