API reference › @evolu/common › Task › createRun
const createRun: CreateRun<RunDeps>;
Defined in: packages/common/src/Task.ts:1186
Creates root Run.
The root Run is also the daemon Run: it stays running until disposed. Child
Runs created by run(task) are disposed by their parent once they settle.
Call once per entry point (main thread, worker, etc.) and dispose on shutdown. All Tasks run as descendants of this root Run.
This common createRun is platform-agnostic. At application entry
points, prefer the platform adapter when one exists. @evolu/web adds
browser error and unhandledrejection handlers, @evolu/nodejs adds
Node.js uncaughtException, unhandledRejection, and graceful shutdown
handling, and @evolu/react-native adds React Native global error handling.
RunDeps provides default dependencies:
Example
// App entry point
await using run = createRun();
const result = await run(fetchData);
Example with custom dependencies
// Define dependency interfaces
interface Config {
readonly apiUrl: string;
}
interface ConfigDep {
readonly config: Config;
}
// Task declares its dependencies via the D type parameter
const fetchUser =
(id: string): Task<User, FetchError, ConfigDep> =>
async (run) => {
const { config } = run.deps;
const response = await fetch(`${config.apiUrl}/users/${id}`);
// ...
};
// Composition root: create a Run with custom deps
type AppDeps = RunDeps & ConfigDep;
const appDeps: AppDeps = {
...testCreateDeps(), // or spread individual deps
config: { apiUrl: "https://api.example.com" },
};
await using run = createRun(appDeps);
// Run type is inferred from the deps argument
const result = await run(fetchUser("123"));
// TypeScript catches missing deps at compile time:
// await using run2 = createRun(); // Run<RunDeps>
// run2(fetchUser("123")); // Error: Property 'config' is missing